-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsquare.c
64 lines (56 loc) · 1.1 KB
/
csquare.c
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
#include<stdio.h>
#include<math.h>
//int mod_expo (long long int , long long int , long long int) ;
int main ()
{
int t , i , j, temp ;
long long int a, b, m , ans , con_num;
scanf ("%d",&t) ;
for (j =1 ; j<=t ; j++)
{
scanf ("%lld%lld%lld",&a , &b,&m) ;
con_num = 0 ;
i = 0 ;
while (b != 0 )
{
temp = b %10 ;
b = b / 10 ;
con_num = con_num + (temp*pow (3,i));
i++ ;
}
ans = 1 ;
a = fmod (a, m) ;
while (con_num > 0 )
{
if (fmod(con_num,2)== 1)
{
ans = fmod ((ans *a), m ) ;
a = a *a ;
a = fmod (a , m ) ;
con_num >>=1 ;
}
}
ans = fmod (ans , m) ;
printf ("%lld\n",ans) ;
}
return 0 ;
//getch();
}
/*
int mod_expo (long long int base , long long int exp , long long int modu )
{
long long int ans = 1 ;
base = fmod (base, modu) ;
while (exp > 0 )
{
if (fmod(exp,2)== 1)
{
ans = fmod ((ans *base), modu ) ;
base = base *base ;
base = fmod (base , modu ) ;
exp >>=1 ;
}
}
return fmod (ans , modu );
}
*/