3
3
import java .io .*;
4
4
import java .math .*;
5
5
6
- /*
6
+ /**
7
7
* Author : joney_000[[email protected] ]
8
- * Algorithm : N/A
8
+ * Algorithm : Extended Euclid Algo: find 3 things X, Y, GCD(A, B) Such that X * A + Y * B = GCD(A, B)
9
+ * Time : O(MAX(A, B)) Space : O(MAX(A, B))
9
10
* Platform : Codeforces
10
- * Ref :
11
+ * Ref : https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/tutorial/
11
12
*/
12
13
13
- class A {
14
+ public class A {
14
15
15
16
private InputStream inputStream ;
16
17
private OutputStream outputStream ;
@@ -19,10 +20,6 @@ class A{
19
20
20
21
private final int BUFFER = 100005 ;
21
22
22
- private int auxInts [] = new int [BUFFER ];
23
- private long auxLongs [] = new long [1 ];
24
- private double auxDoubles [] = new double [1 ];
25
- private char auxChars [] = new char [1 ];
26
23
private final long mod = 1000000000 +7 ;
27
24
private final int INF = Integer .MAX_VALUE ;
28
25
private final long INF_L = Long .MAX_VALUE / 10 ;
@@ -40,14 +37,11 @@ public A(boolean stdIO)throws FileNotFoundException{
40
37
in = new FastReader (inputStream );
41
38
out = new PrintWriter (outputStream );
42
39
}
43
-
40
+
44
41
void run ()throws Exception {
45
42
int n = i ();
46
-
47
- int ans = 0 ;
48
-
43
+ long ans = 0 ;
49
44
out .write ("" +ans +"\n " );
50
-
51
45
}
52
46
53
47
void clear (){
@@ -77,10 +71,10 @@ long pow(long a, long b, long mod){
77
71
if (b == 0 )return 1 ;
78
72
if (b == 1 )return a ;
79
73
long ans = pow (a , b /2 , mod );
80
- ans = (ans * ans );
74
+ ans = mulMod (ans , ans , mod );
81
75
if (ans >= mod )ans %= mod ;
82
76
83
- if (b % 2 == 1 )ans = ( a * ans );
77
+ if (b % 2 == 1 )ans = mulMod ( a , ans , mod );
84
78
if (ans >= mod )ans %= mod ;
85
79
86
80
return ans ;
@@ -107,46 +101,26 @@ int i()throws Exception{
107
101
return in .nextInt ();
108
102
}
109
103
110
- int [] is (int n )throws Exception {
111
- for (int i =1 ; i <= n ;i ++)auxInts [i ] = in .nextInt ();
112
- return auxInts ;
113
- }
114
-
115
104
long l ()throws Exception {
116
105
return in .nextLong ();
117
106
}
118
107
119
- long [] ls (int n )throws Exception {
120
- for (int i =1 ; i <= n ;i ++)auxLongs [i ] = in .nextLong ();
121
- return auxLongs ;
122
- }
123
-
124
108
double d ()throws Exception {
125
109
return in .nextDouble ();
126
110
}
127
111
128
- double [] ds (int n )throws Exception {
129
- for (int i =1 ; i <= n ;i ++)auxDoubles [i ] = in .nextDouble ();
130
- return auxDoubles ;
131
- }
132
-
133
112
char c ()throws Exception {
134
113
return in .nextCharacter ();
135
114
}
136
115
137
- char [] cs (int n )throws Exception {
138
- for (int i =1 ; i <= n ;i ++)auxChars [i ] = in .nextCharacter ();
139
- return auxChars ;
140
- }
141
-
142
116
String s ()throws Exception {
143
117
return in .nextLine ();
144
118
}
145
119
146
120
BigInteger bi ()throws Exception {
147
121
return in .nextBigInteger ();
148
122
}
149
-
123
+
150
124
private void closeResources (){
151
125
out .flush ();
152
126
out .close ();
0 commit comments