hdu 1576 A/B

使用exgcd解决HDOJ简单问题

http://acm.hdu.edu.cn/showproblem.php?pid=1576

  简单exgcd应用。。。无压力1y。。。。

View Code
 1 /*
 2  * Author: SCAU_Lyon
 3  * Problem: hdu 1576
 4  * Method: ex-gcd
 5  */
 6 
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cmath>
10 #include <algorithm>
11 #include <cassert>
12 
13 using namespace std;
14 typedef __int64 ll;
15 const int mod = 9973;
16 
17 void exgcd(int a, int b, ll &x, ll &y, int &d){
18     if (b){
19         exgcd(b, a % b, y, x, d);
20         y -= (a / b) *x;
21     }
22     else{
23         d = a;
24         x = 1;
25         y = 0;
26     }
27 }
28 
29 int main(){
30     int n, b, d;
31     int T;
32     ll x, y;
33 
34     scanf("%d", &T);
35     while (T-- && scanf("%d%d", &n, &b)){
36         exgcd(b, mod, x, y, d);
37         assert(d == 1);
38         x *= n;
39         x %= mod;
40         while (x < 0) x += mod;
41         printf("%I64d\n", x);
42     }
43 
44     return 0;
45 }

 

——written by Lyon

转载于:https://www.cnblogs.com/LyonLys/archive/2012/09/18/hdu_1576_Lyon.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值