View Code
#include<stdio.h> int x, y; void kzgcd(int a,int b) { if(!b) x = 1, y = 0; else { kzgcd(b,a%b); int t = y; y = x-(a/b)*y; x = t; } } int main() { int T, n, b; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&b); kzgcd(b,9973); while(x < 0) x += 9973; printf("%d\n",x*n%9973); } return 0; }
欧几里得拓展,理解不了欧几里得是干啥的。显摆到这里吧