【数论】HDU 1576
来源:互联网 发布:数据流图数据字典实例 编辑:程序博客网 时间:2024/05/16 18:46
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4659 Accepted Submission(s): 3627
Problem Description
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
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<cstdio>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define MAXN#define MAXM#define MOD 9973#define INF 0x3f3f3f3ftypedef long long int LL;LL A,B;LL exgcd(LL a,LL b,LL &x,LL&y){ if(b==0) { x=1,y=0; return a; } LL rn=exgcd(b,a%b,x,y); LL t=x; x=y; y=t-(a/b)*y; return rn;}LL getny(LL a,LL mod){ LL x,y; exgcd(a,mod,x,y); x=x%MOD; if(x<0)x+=mod; return x;}int main(){ int Case; scanf("%d",&Case); while(Case--) { scanf("%I64d%I64d",&A,&B); printf("%I64d\n",((A*getny(B,MOD)%MOD)%MOD)); }}
2 0
- 【数论】HDU 1576
- HDU 1576 A/B(数论)
- HDU 1576 A/B 数论水题
- hdu 1576(数论之扩展欧几里得)
- [HDU](1576) A/B ----扩展欧几里德(数论)
- hdu 1576 A/B || hdu 2669 Romantic (数论--欧几里德)
- HDU 2204 (数论)
- 数论 MillerRabin hdu 3792
- HDU 3123 数论
- 【数论】HDU-4196-Remoteland
- HDU 3988 数论
- HDU 1787 数论
- hdu 1395 数论
- HDU 2104数论 欧几里得
- HDU 1060 数论
- HDU 2161 Primes 数论
- HDU 1695 GCD 数论
- HDU 1568 Fibonacci 数论
- Alluxio架构图-总
- macos 使用技巧
- linux服务器实例MYSQL每日备份脚本
- 怎样合法地打造一个属于自己的商业情报网络?
- 花指令入门
- 【数论】HDU 1576
- HTTP Status 404(The requested resource is not available)的几种解决方案
- 新起点 为了自己的兴趣出发
- webpack gulp for window
- 实现下拉框显示所有曾经登陆的用户名的小功能
- Android四大组件之------Activity
- 作用域安全的构造函数
- 商品订购及货物采购信息系统(代码分析)
- 一些小记录