-
Notifications
You must be signed in to change notification settings - Fork 182
/
A.cpp
117 lines (97 loc) · 1.72 KB
/
A.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
#include<bits/stdc++.h>
/*Author - Silent Knight
Institution - Birla Institute Of Technology, Mesra
*/
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
ll modInverse(ll n,ll p)
{
ll x = n;
ll y = p-2;
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll nCrModPFermat(ll n,ll r,ll p)
{
if (r == 0)
return 1;
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]*modInverse(fac[r], p) % p*modInverse(fac[n-r], p) % p) % p;
}
ll fun1(string s,string k,ll n)
{
ll i,j;
ll a = 0,b = 0,x = 0;
ll g[4]={0};
ll p=1e9+7;
ll sum=0;
for(i=0;i<n;i++)
{
if(s[i]=='1')
a++;
if(k[i]=='1')
b++;
}
if(a>b)
{
x=1;
}
g[0]=(a-b)*x;
g[1]=(1-x)*(b-a);
g[2]=(n-a)*x+(1-x)*(n-b);
g[3]=b*x+(1-x)*a;
do{
sum=(sum+ nCrModPFermat(n, g[0]+g[1], p))%p;
g[0] += 1;
g[1] += 1;
g[2] -= 1;
g[3] -= 1;
}while(g[2]>=0 && g[3]>=0);
return sum;
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//sabse bekaar solution of the world!!!!!!
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll ans;
if(n%2 == 0)
ans = (n/2) - 1;
else
ans = n/2;
cout<<ans<<"\n";
}
return 0;
}