扩展欧几里得算法吧!!应该是基础的那种,不过自己好久没有做题目了,又重新把知识点看了一次,现在基本知道个意思了吧!!!
发现打代码这个东西还是要经常玩玩,不然很快就会忘记的......
题目公式:x*b-9973*y=n;求出x就行啦!!!
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include <algorithm>
typedef long long ll;
using namespace std;
void exgcd(int a,int b,int &x,int &y){
if(b == 0){
x=1;y=0;
}
else{
exgcd(b,a%b,y,x);
y-=x*(a/b);
}
}
int main(){
int t,n,b,i;
int x,y;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&b);
exgcd(b,9973,x,y); //这时候的x是当n=1时候的,所以要乘以n;
x*=n;
x=x%9973;
if(x < 0) x+=9973;
printf("%d\n",x);
}
return 0;
}
坚持.......