您的位置:首页 > 其它

hdu 1576 扩展欧几里得

2013-07-05 22:16 288 查看
#include<cstdio>
#include<iostream>
#include<algorithm>
typedef __int64 LL;
const LL mod = 9973;
using namespace std;
LL gcd(LL a,LL b)
{
return b==0?a:gcd(b,a%b);
}
void gcd(LL a,LL b,LL& d,LL& x,LL& y)
{
if(!b)
{
d=a;
x=1;
y=0;
}
else
{
gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
int main()
{
LL b,n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d",&n,&b);
LL x=0,y=0;
LL d=1;
gcd(b,mod,d,x,y);
while(x<0||y>0)
{
x+=mod;
y-=b;
}
//printf("%I64d\n",x);
printf("%I64d\n",(n*x)%mod);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数学