Given a, b, c find the value of ab mod c (1 ≤ a, b, c < 263).
Input
Contains multiple test cases. Each test is given in one line and contains three integers a, b and c.
Output
For each test case print on a separate line the value of ab mod c.
Example 1
Input example #1
3 2 4
2 10 1000
Output example #1
1
24
数据相乘爆long long,用快速乘。
当然了还有更巧妙的奇淫巧计:
long long ksc(long long x,long long y,long long mod)
{
long long z=(long double)x/mod*y;
long long res=(usigned long long)x*y-(usigned long long)z*mod;
return (res+mod)%mod;
}
// 一种自动溢出的数据类型(存满了就会自动变为0)
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <string>
using namespace std;
//for(i=1;i<n;i++)
//scanf("%d",&n);
//printf("\n",);
long long tree[400000],c;
long long f(long long a,long long b)
{
long long temp=0;
while(b!=0)
{
if(b%2==1)
{
temp+=a;
temp%=c;
}
a+=a;
a%=c;
b>>=1;
}
return temp;
}
int main()
{
long long i,j,k,a,b;
while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
{
a%=c;
k=1;
while(b!=0)
{
if(b%2==1)
{
k=f(k,a);
k%=c;
}
a=f(a,a);
a%=c;
b>>=1;
}
printf("%lld\n",k);
}
//memset(num,0,sizeof(num));
return 0;
}