HDU 1576 A/B
2016-07-11 15:53
501 查看
Problem Description
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
【题目分析】
其实就是用拓展的欧几里得算法求一下乘法逆元就可以了。
【代码】
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
【题目分析】
其实就是用拓展的欧几里得算法求一下乘法逆元就可以了。
【代码】
#include <cstdio> inline void exgcd(int a,int b,int &x,int &y) { if (!b) {x=1,y=0;return ;} exgcd(b,a%b,x,y); int t=x; x=y; y=t-a/b*y; } int main() { int T,x,y; scanf("%d",&T); while (T--) { int n,b; scanf("%d%d",&n,&b); exgcd(b,9973,x,y); printf("%d\n",((n*x)%9973+9973)%9973); } }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- HDU 1016 Prime Ring Problem
- HDU 1017 A Mathematical Curiosity