-
Notifications
You must be signed in to change notification settings - Fork 0
/
REC__ud.c
80 lines (78 loc) · 975 Bytes
/
REC__ud.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define ll long long int
int lp[MAX];
void siever(void)
{
int i,j;
for(i=2;i<MAX;++i)
{
if(lp[i]==0)
{
for(j=i;j<MAX;j+=i)
lp[j]=i;
}
}
}
int phi(int n)
{
int i;
int div;
int ans;
ans=n;
while(n!=1)
{
div=lp[n];
ans/=div;
ans*=div-1;
while(n%div==0)
{
n/=div;
}
}
return ans;
}
ll modexp(ll a, ll b, ll m)
{
if(b==1) return a;
ll res=1;
while(b)
{
if(b&1) res=(res*a)%m;
a=(a*a)%m;
b/=2;
}
return res;
}
ll gcd(string s, ll m)
{
ll res=0;
int i;
string::iterator is;
for(is=s.begin();is!=s.end();++is)
{
i=*is-'0';
res=((res*10)%m + i%m)%m;
}
return res;
}
int main()
{
siever();
int t;
cin>>t;
while(t--)
{
string a,b,n;
ll m;
cin>>a>>b>>n>>m;
ll aa,bb,nn;
aa=gcd(a,m);
bb=gcd(b,m);
nn=gcd(n,m);
ll an=modexp(aa,nn,
)
}
return 0;
}