-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate.cpp
110 lines (85 loc) · 1.85 KB
/
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
#include<bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define mp(x,y) make_pair(x,y)
using namespace std;
ll gcd (ll a,ll b) {
if (a == 0)
return b;
return gcd(b % a,a);
}
ll lcm (ll a,ll b) {
return (a * b) / gcd(a,b);
}
ll digit_sum (ll n) {
ll sum{};
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
bool is_prime (ll n) {
bool p{true};
for (ll i{2};i * i <= n;++i) {
if (n % i == 0) {
p = false;
break;
}
}
return p;
}
ll pow_mod(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1)
res = (res*x) % p;
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
ll mod_inverse (ll a,ll m) { // m must be prime
return pow_mod(a,m - 2,m);
}
ll factorial_mod (int n,ll m) { // O(n) time
ll cur = 1;
for (int i = 1;i <= n;++i) {
cur = ((cur % m) * (i * 1LL % m)) % m;
}
return cur;
}
ll ncr (int n,int r,ll m) {
// NOTE: precompute factorials & inverses for multiple testcases / iterations
if (r < 0 || r > n)
return 0;
return (((factorial_mod(n,m) * mod_inverse(factorial_mod(n - r,m),m)) % MOD)
* mod_inverse(factorial_mod(r,m),m)) % MOD;
}
ll npr (int n,int r,ll m) {
// NOTE: precompute factorials & inverses for multiple testcases / iterations
if (r < 0 || r > n)
return 0;
return (factorial_mod(n,m) * mod_inverse(factorial_mod(n - r,m),m)) % MOD;
}
void shadow () {
int tt{1};
cin >> tt;
while (tt--) {
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
shadow();
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}