A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10934 Accepted Submission(s): 8757
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 乘法逆元
#include<iostream> #include<string.h> #include<math.h> #define max 0x3f3f3f3f #define ll long long #define mod 1000000007 using namespace std; ll x,y; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } void exgcd(ll a, ll b, ll &x, ll &y) //拓展欧几里得算法 { if(!b) x = 1, y = 0; else { exgcd(b, a % b, y, x); y -= x * (a / b); } } ll niyuan(ll a, ll b) //求a对b取模的逆元 { ll x, y; exgcd(a, b, x, y); return (x + b) % b; } int main() { ll n,m,t; scanf("%lld",&t); while(t--) { scanf("%lld%lld",&n,&m); m=niyuan(m,9973); printf("%lld\n",n*m%9973); } }