/*///暴力枚举求素数
for(int i=2;i<=n;i++)
{
bool g=0;
for(int j=2;j*j<=i;j++)
if(i%j==0)
{
g=1;
break;
}
if(g==0)
{
tot++;
p[tot]=i;
}
}
///普通筛法
for(int i=2;i<=n;i++)
if(prime[i]==0)
{
p[++tot]=i;
for(int j=2;j*i<=n;j++)
prime[j*i]=1;
}
///线性筛法 将每一个合数
for(int i=2;i<=n;i++)
{
if(prime[i]==0)
p[++tot]=i;
for(int j=1;j<=tot && i*p[j]<=n;j++)
{
prime[i*p[j]] = 1;
if(i%p[j]==0)
break;
}
}
///快速幂 a^b
///逆元
///gcd
int gcd (int a,int b)
{
if(b==0) return a;
else
return gcd(b,a%b);
}
///拓展欧几里得
int ex_gcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
int r=ex_gcd(b,a%b,x,y);
int t=x;
x=y;
y=t-(a/b)*y;
return y;
}
*/
/*
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int t;
LL m,n;
cin>>t;
while(t--)
{
scanf("%lld %lld",&m,&n);
if(m==1 || n==1)
{
cout<<"NO"<<endl;
continue;
}
if((m%2==0 && n%2==0) || (__gcd(m,n)==m || __gcd(m,n)==n))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
*/
/*
#include <bits/stdc++.h>
using namespace std;
int main()
{
int p,q;
while(cin>>p>>q)
cout<<p+q-__gcd(p,q)<<endl;
}
*/
/*
#include <bits/stdc++.h>
using namespace std;
int main()
{
int p,q;
while(cin>>p>>q)
cout<<p*q/__gcd(p,q)<<endl;
}
*/
/*
///快速幂模板 a^b%c
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long LL;
LL mod (LL a,LL b,LL c)
{
LL ans =1;
a=a%c;
while(b>0)
{
if((b&1)==1)
ans=(ans*a)%c;
b>>=1;
a=(a*a)%c;
}
return ans;
}
bool isprime(LL x)
{
LL i,j,k=(int)sqrt(x);
if((x==2)||(x==3))
return 1;
if(x==0)
return 0;
for(i=2;i<=k;i++)
if(x%i==0)
return 0;
return 1;
}
int main()
{
LL p,m,result;
while(scanf("%lld %lld",&p,&m))
{
if((p==0) && (m==0))
break;
if(isprime(p))
cout<<"no"<<endl;
else
{
if(mod(m,p,p)==m)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}
return 0;
}
*/
/*
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
LL M,N,i,n,a,b,c,sum;
scanf("%lld",&N);
while(N--)
{
scanf("%lld%lld",&M,&n);
sum=0;
for(i=0;i<n;i++)
{
c=1;
scanf("%lld%lld",&a,&b);
while(b)
{
if(b&1)
c=c*a%M;
a=a*a%M;
b/=2;
}
sum=sum+c%M;
}
printf("%lld",sum%M);
}
}
*/
///a^b%c
/*
LL mod (LL a, LL b, LL c)
{
LL ans =1;
a=a%c;
while(b)
{
if(b&1)
ans=(ans*a)%c;
b>>=1; ///等价于b/2
a=(a*a)%c;
}
return ans;
}
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod (LL a,LL b,LL c)
{
LL ans =1;
while(b)
{
if(b&1)
ans=(ans*a)%c;
b>>=1;
a=(a*a)%c;
}
return ans;
}
int main()
{
int a,b;
while(scanf("%d %d",&a,&b) , (a || b))
{
printf("lld\n",mod(a,b,1000));
}
}
快速幂、欧几里得算法
最新推荐文章于 2023-04-11 19:56:38 发布