hdu1576- A/B

分析: ( A / B )%9973 = ans ,   A / B =  ans + K*9973 ;   

               A = ans * B  + K*9973*B   ; 又因为 A %  9973 = n;

             ( ans * B )%9973=n      ans*B=n+9973*K;

             ( ans / n ) * B + (-K / n ) *9973 =1 

            x=  ans / n   ,      y= -K / n;


 #include 
#include 
#include 
#include 
using namespace std;
int E_GCD(int a, int b, int &x, int &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	int ans = E_GCD(b, a%b, x, y);
	int tem = x;
	x = y;
	y = tem - a / b*y;
	return ans;
}
int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		int b, n;
		int x, y;
		scanf("%d%d", &n, &b);
		E_GCD(b, 9973, x, y);
		x = (x%9973 + 9973) % 9973;
		printf("%d\n", (x*n) % 9973);
	}
}



你可能感兴趣的:(数学)