-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfactorial.sublime-snippet
52 lines (48 loc) · 1.05 KB
/
factorial.sublime-snippet
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
<snippet>
<content><![CDATA[
vi fac,inv;
ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
ll ans = 1;
while(exponent !=0 ) {
if((exponent&1) == 1) {
ans = ans*base ;
ans = ans%mod;
}
base = base*base;
base %= mod;
exponent>>= 1;
}
return ans%mod;
}
ll add(ll a,ll b,ll mod=hell)
{
return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a,ll b,ll mod=hell)
{
return ((a%mod)-(b%mod)+mod)%mod;
}
ll mul(ll a,ll b,ll mod=hell)
{
return ((a%mod)*(b%mod))%mod;
}
void cal_fac()
{
fac.pb(1);
rep(i,1,N)
fac.pb(mul(fac.back(),i));
rep(i,0,N)
inv.pb(expo(fac[i],hell-2,hell));
}
ll C(ll n,ll r)
{
if(r>n)
return 0;
return mul(fac[n],mul(inv[n-r],inv[r]));
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>factorial</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>