码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1576 A/B

时间:2015-06-01 22:32:49      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

hdu 1576 A/B

标签:

原文地址:http://blog.csdn.net/xinag578/article/details/46317279

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!