I

要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。

Input

数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。

Output

对应每组数据输出(A/B)%9973。

Sample Input

2
1000 53
87 123456789

Sample Output

7922
6060

瞎jb用了一下逆元就直接ac了,对于逆元还是有点不知不解的

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define cl clear()
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=9973;
using namespace std;
const double pi=acos(-1.0);
ll a,b;
ll niyuan(ll a)
{
	ll r=1,b=9971,ans=a;
	while(b)
	{
		if(b&1) r=ans*r%mod;
		ans=ans*ans%mod;
		b>>=1; 
	}
	return r;
}
ll solve(ll a,ll b)
{
	return a*niyuan(b)%mod;
}
int main()
{
	int re;
	cin>>re;
	while(re--)
	{
		cin>>a>>b;
		cout<<solve(a,b)<<endl;
	}
}
原文地址:https://www.cnblogs.com/wzl19981116/p/9354461.html