hdu 1576 A/B

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int M=9973;
typedef long long ll;

void gcd(ll a, ll b, ll& d,ll& x, ll& y)
{
    if(b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        gcd(b,a%b,d,y,x);
        y-=(a/b)*x;
    }
}
int main()
{
    int t;
    ll n,b,x,y,d,ans;
    scanf("%d",&t);
    while(t--)
    {
        cin>>n>>b;
        gcd(b,-M,d,x,y);
        x*=n/d;
        while(x<0) x+=M;
        cout<<x<<endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

原文地址:https://www.cnblogs.com/xryz/p/4847973.html