-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCsquare_temp.cpp
More file actions
53 lines (48 loc) · 1.06 KB
/
Csquare_temp.cpp
File metadata and controls
53 lines (48 loc) · 1.06 KB
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
#include<stdio.h>
#include<conio.h>
int pow_2(int a, int b){
if (b==1) return a;
if(b==0) return 1;
int temp=pow_2(a,b/2);
if(b&1)
return temp*temp*a;
return temp*temp;
}
static int a,b,m;
int convert(int b){
int temp=0,cntr=0;
int p=b;
int i=0,j;
while(p>0){
j=p%10;
//printf("%d\n",j);
//printf("%d\n",pow(3,i));
temp=temp+j*pow_2(3,i);
//printf("%d\n",temp);
p/=10;
i++;
}
return temp;
}
int answer(){
int ans=1;
while(b>=1){
if(b&1)
ans=(ans*(a%m))%m;
a=a*a;
b=b>>1;
}
return ans;
}
int main(){
scanf("%d",&t);
while(t>0){
scanf("%d %d %d",&a,&b,&m);
b=convert(b);
int an=answer();
printf("a:%d b:%d ans:%d\n",a,b,an);
t--;
}
//getch();
return 0;
}