-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber-Theory_template.cpp
146 lines (123 loc) · 3.96 KB
/
Number-Theory_template.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
▄ ██ ▄ ▄█ ▄███▄ █▄▄▄▄ ███ ▄███▄ ██ ▄▄▄▄▄ ▄▄▄▄▀
▀▄ █ █ █ █ ██ █▀ ▀ █ ▄▀ █ █ █▀ ▀ █ █ █ ▀▄ ▀▀▀ █
█ ▀ █▄▄█ █ █ ██ ██▄▄ █▀▀▌ █ ▀ ▄ ██▄▄ █▄▄█ ▄ ▀▀▀▀▄ █
▄ █ █ █ █ █ ▐█ █▄ ▄▀ █ █ █ ▄▀ █▄ ▄▀ █ █ ▀▄▄▄▄▀ █
█ ▀▄ █ █ █ ▐ ▀███▀ █ ███ ▀███▀ █ ▀
▀ █ █▐ ▀ █
▀ ▐ ▀
*/
/**
* xavierbeast68
* URL :
* AVOIDING COMPLEXITY, REDUCES BUGS.
*/
/*
*Thought Process*
!---------------!
*/
#include<bits/stdc++.h>
using namespace std;
#define JULI_OP ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long
#define endl '\n'
#define fo(i, a, b) for(int i = a; i <= b; ++i)
#define repl(it, var) for(auto &it : var)
#define all(x) begin(x), end(x)
const int mod1 = 1e9+7;
const int mod2 = 998244353;
const int INF = 1000000000000000005;
template<class T> using v = vector<T>;
template<class T>istream& operator>>(istream &in, vector<T> &a){for(auto &i: a){in >> i;} return in;}
template<class T>ostream& operator<<(ostream &os, vector<T> &a){int sz = a.size();for(int i = 0 ; i < sz; ++i){os << a[i] << " \n"[i==sz-1];}return os;}
// <---------- Global Variables ---------->
int n;
// string s;
// v<int> vec;
// <-------------------------- Helper Functions -------------------------->
// binary exponentiation
/*Recursive->
int binpow(int a, int b){
if(b == 0) return 1;
int res = binpow(a, b/2);
if(b%2 == 0) return res*res;
return res*res*a;
}
*/
/*Iterative Modular Exponentiation*/
int modExpo(int a, int b, int mod) {
a %= mod;
int res = 1;
// binary exponentiation
// while(b){
// if(b%2) res *= a;
// a *= a;
// b /= 2;
// }
// faster, modular exponentiation
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
// modular arithematic
int _mod(int a, int mod){return (a+mod)%mod;}
// based on fermat-little theorem, mod should be prime, TC->O(log2(mod))
// 1/a = a^(mod-2)
int modInv(int a, int mod){return modExpo(_mod(a, mod), mod-2, mod);}
int modAdd(int a, int b, int mod){return (_mod(a, mod) + _mod(b, mod))%mod;}
int modSub(int a, int b, int mod){return (_mod(a, mod) - _mod(b, mod))%mod;}
int modMul(int a, int b, int mod){return (_mod(a, mod) * _mod(b, mod))%mod;}
int modDiv(int a, int b, int mod){return modMul(_mod(a, mod), modInv(_mod(b, mod), mod), mod);}
// primality test
bool isPrime(int n){
for(int i = 2; i*i <= n; i++){
if(n%i == 0) return false;
}
return true;
}
// sieve of eratosthenes
int build = 0;
vector<bool> prime;
int sz = 1e6+5;
void buildSieve(){
if(build == 1) return;
build = 1;
prime.resize(sz, true);
prime[0] = prime[1] = false;
for(int i = 2; i*i < sz; ++i){
if(prime[i] == true){
for(int j = i*i; j < sz; j += i){
prime[j] = false;
}
}
}
}
// Prime Factorization
vector<int> factors(int n){
vector<int> facts;
for(int d = 2; d*d <= n; d++){
while(n%d == 0){
facts.push_back(d);
n /= d;
}
}
if(n > 1) facts.push_back(n);
return facts;
}
// <-------------------------- Solve Function -------------------------->
void solve(){
}
// <-------------------------- Main -------------------------->
signed main(){
JULI_OP; // FAST_IO
int testcases = 1;
// cin >> testcases;
while(testcases--){
solve();
}
return 0;
}