-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf.cpp
More file actions
59 lines (48 loc) · 854 Bytes
/
cf.cpp
File metadata and controls
59 lines (48 loc) · 854 Bytes
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
ll exponent(ll base, ll p, ll m)
{
ll res=1;
while(p>0)
{
if(p&1) res=(res*base)%m;
p=p>>1;
base=(base*base)%m;
}
return res;
}
ll GP(ll n,ll power2,ll r,ll m)
{
if(n==1) return 1;
ll res;
if(n&1)
{
res=exponent(r,(n-1)*power2,m);
}
else res=0;
res=res+((1+exponent(r,power2,m))*GP(n/2,power2*2,r,m))%m;
return res;
}
ll t,a,n,m,k,res,ans,d,x,num;
int main()
{
cin>>t;
while(t--)
{
cin>>a>>n>>m;
num=a;
d=0;
while(num>0)
{
d++;
num=num/10;
}
x=1;
for(int i=1;i<=d;i++)
{
x=x*10;
}
res=0;
res=(a*GP(n,1,x,m))%m;
cout<<res<<endl;
}
return 0;
}