标签:des style http color os io 数据 ar
2 1000 53 87 123456789
7922 6060
void gcd(int a,int b,int &x,int &y)//扩展gcd,可以求出gcd(a,b)以及ax+by=gcd(a,b)中x,y的值 { if(!b) { x=1; y=0; return ; } else { gcd(b,a%b,x,y); int temp=x; x=y; y=temp-a/b*y; } }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<limits.h> typedef long long LL; using namespace std; const int MOD=9973; void gcd(int a,int b,int &x,int &y) { if(!b) { x=1; y=0; return ; } else { gcd(b,a%b,x,y); int temp=x; x=y; y=temp-a/b*y; } } int main() { int t,n,b,x,y; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&b); gcd(b,MOD,x,y); x*=n; int tep=(x%MOD+MOD)%MOD; printf("%d\n",tep); } return 0; }
HDU 1576 A/B(拓展欧几里得),布布扣,bubuko.com
标签:des style http color os io 数据 ar
原文地址:http://blog.csdn.net/u013582254/article/details/38663029