Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long int mod(long long x,long long n,long long int m)
- {
- if(n==0)
- return 1;
- if(n%2==1)
- return (((x%m)*mod(x,n-1,m))%m);
- else{
- long long int d=mod(x,n/2,m);
- return (((d%m)*(d%m))%m);
- }
- }
- int main()
- {
- long long int a,b,c,i,j,x,n,m,t;
- while(cin>>t)
- {
- if(t==0)
- break;
- else
- {
- for(i=0;i<t;i++)
- {
- cin>>x>>n>>m;
- a=mod(x,n,m);
- cout<<a<<endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement