hdu1576
来源:互联网 发布:蜗牛睡眠知乎 编辑:程序博客网 时间:2024/05/16 12:18
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4534 Accepted Submission(s): 3524Problem 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 Input21000 5387 123456789Sample Output79226060Authorxhd设ans=(A/B)%9973
则(A/B)=ans(mod 9973)
A=(b*ans)(mod 9973)
(A%9973)=(b*ans)(mod 9973)
n=(b*ans)(mod 9973)
b*ans=n(mod 9973)
求ans,利用扩展欧几里德解线性同余方程即可
#include<stdio.h>#define LL long longvoid exgcd(LL a,LL b,LL &d,LL &x,LL &y){ if(b==0) { d=a; x=1; y=0; } else { exgcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { int t; LL n,b,d,x,y; scanf("%d",&t); while(t--) { scanf("%lld%lld",&n,&b); exgcd(b,9973,d,x,y); x=(x*n%9973+9973)%9973; printf("%lld\n",x); } return 0; }
0 0
- hdu1576
- hdu1576
- hdu1576
- hdu1576
- hdu1576 ex_gcd
- hdu1576-A/B
- HDU1576 扩展欧几里得
- hdu1576 A/B
- hdu1576 A/B
- hdu1576- A/B
- HDU1576 A/B
- hdu1576 扩展欧几里得
- HDU1576 解方程....
- #HDU1576# A/B
- A/B HDU1576
- HDU1576 A/B
- A/B(HDU1576)
- hdu1576 A/B (扩展欧几里德)
- R中快速计算欧式距离
- 7.15 J codeforces 681E Runaway to a Shadow
- R做时间序列(ARIMA)的案例
- 八皇后
- SQL Server 复制表及数据的两种方法
- hdu1576
- 通过SQL语句提取存储过程中的内容
- C语言笔记 lesson4 char类型
- stm32 后缀命名含义
- 【原创】PB开发Web Service接口环境搭建及问题解决
- HDU-5877-Weak Pair(离散+树状数组)
- bzoj1087: [SCOI2005]互不侵犯King
- jQuery或者js保存文件到本地
- [初级教程]samsung s3c2416x 的启动方式