HDU1576 A/B 扩展欧几里德简单题
来源:互联网 发布:北风网大数据百度云 编辑:程序博客网 时间:2024/06/06 01:02
本题很简单
A%9973=n;
那么
n=A-A/9973*9973;
设 A/B=X;
代入方程
n=B*X-A/9973*9973
然后这个方程中的 A/9973不要去纠结它,A的值就当不知道,然后 方程可变成二元方程 B*X-9973*Y=n;
这下符合 exgcd的基本式子了
求出 X, 由于 A/B=X,所以X=A/B,那么 X%9973 其实就是 (A*B)%9973
#include<iostream>#include<cstdio>#include<list>#include<algorithm>#include<cstring>#include<string>#include<queue>#include<stack>#include<map>#include<vector>#include<cmath>#include<memory.h>#include<set>#define ll long long#define LL __int64#define eps 1e-8//const ll INF=9999999999999;#define M 400000100#define inf 0xfffffffusing namespace std;//vector<pair<int,int> > G;//typedef pair<int,int> P;//vector<pair<int,int>> ::iterator iter;////map<ll,int>mp;//map<ll,int>::iterator p;//vector<int>G[30012];LL extgcd(LL a,LL &x,LL b,LL &y){if(b==0){x=1;y=0;return a;}LL r=extgcd(b,x,a%b,y);LL t=x;x=y;y=t-a/b*y;return r;}int main(void){int t;cin>>t;LL n,b;while(t--){cin>>n>>b;LL t0,p0;LL gcd=extgcd(b,t0,9973,p0);/*t0=(t0+n)%n;*/LL t=t0*n/gcd;t=(t%9973+9973)%9973;cout<<t<<endl;}}
- HDU1576 A/B 扩展欧几里德简单题
- hdu1576 A/B (扩展欧几里德)
- Hdu1576 A-A/B 扩展欧几里德
- hdu1576 A/B(扩展的欧几里德算法)
- hdu1576 A/B 扩展欧几里德算法
- HDU1576 A/B 扩展欧几里得
- HDU1576 A/B(扩展欧几里得)
- [hdu1576]: A/b (扩展欧几里得)
- hdu1576 A/B 扩展欧几里得求逆元
- hdu1576(A/B)扩展欧几里得
- HDU1576 A/B (扩展欧几里得求逆元)
- hdu1576-A/B
- hdu1576 A/B
- hdu1576 A/B
- hdu1576- A/B
- HDU1576 A/B
- #HDU1576# A/B
- A/B HDU1576
- 通用hash表
- 找工作总结-机会往往留给有准备的人
- 常用sql001_partition by 以及 row_number()和 dense_rank()和rank()区别
- C#连接Access数据库提示from子语句语法错误
- libclntsh.so.11.1不能识别,解决办法
- HDU1576 A/B 扩展欧几里德简单题
- 【PAT】1067. Sort with Swap(0,*)
- 最原始webservice 部署 axis
- 有一个随机函数fun()能产生0<=X<n的数,现在要用fun()函数来产生0<=Z<m的数。
- 奇异局势
- NSLog在Release版本也会调用 - - NSAssert NSCAssert
- android导入项目 failed to create buildconfig class
- Documentation_power_apm-acpi
- 导Excel,具有下载页面