HDU——1576 A/B
2024-10-20 04:00:28
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6412 Accepted Submission(s): 5069
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)。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
Output
对应每组数据输出(A/B)%9973。
Sample Input
2
1000 53
87 123456789
Sample Output
7922
6060
Author
xhd
Source
思路:
(a/b)mod p=?
定义 c为b在mod p意义下的逆元
=a*c mod p = (a mod p * c mod p)mod p
这样我们就有把这道题转换成裸地扩展欧几里得了。。。
代码:
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,m,t,a,b,x,y,gcd,ans; int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getchar();} return x*f; } int exgcd(int a,int b,int &x,int &y) { ) { x=,y=; return a; } int r=exgcd(b,a%b,x,y),tmp; tmp=x,x=y,y=tmp-a/b*y; return r; } int main() { t=read(); while(t--) { n=read(),m=read(); a=m;b=; gcd=exgcd(a,b,x,y); ) x+=b/gcd; ans=(n%b*x%b)%b; printf("%d\n",ans); } ; }
最新文章
- Linux之CentOS 常用命令
- 重写ajax方法实现异步请求session过期时跳转登录页面
- 《BI那点儿事》三国人物智力分布状态分析
- ubuntu开机遇到-您的当前网络有.local域,我们不建议这样做而且这与AVAHI网络服务探测不兼容。该服务已被禁用
- C#获取程序所在目录路径
- 分享web前端七款HTML5 Loading动画特效集锦
- Spring MVC之LocaleResolver(解析用户区域)
- POJ 1845
- c#图像处理入门
- ORACLE备份手记
- 使用python写appium用例
- 使用ABP打造SAAS系统(1)——环境准备
- 模块化编程node
- Crash CodeForces - 417B
- PHP 环境搭建篇
- Base64 image
- Automatically migrating data to new machines kafka集群扩充迁移topic
- MVC中的分部视图
- Spring之AOP由浅入深
- turtle库实现汉诺塔