POJ 2115(解线性同余方程)
来源:互联网 发布:英雄联盟 mac 国服 编辑:程序博客网 时间:2024/05/17 23:20
与POJ 1061青蛙很像。
注意:for(int i=2;i!=1;i++) 循环到 i 值溢出时,会重新从0开始加。
#include<cstdio>#include<cmath>#include<algorithm>#define ll long longusing namespace std;void gcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b){d=a;x=1;y=0;} else{ gcd(b,a%b,d,y,x);y-=x*(a/b);}}int main(){ ll a,b,c,k; while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&k)&&(a||b||c||k)){ ll M = 1ll<<k; ll d,x,y; gcd(c,M,d,x,y); ll C = b-a; if(C%d!=0){ //如果推导的公式中的B-A不是d的倍数,则一定无解 printf("FOREVER\n"); }else{ x = (x*(C/d))%M; //gcd中的x的最小整数解 ll ans = (x%(M/d)+M/d)%(M/d); //通式(结果)的最小正整数解。 printf("%lld\n",ans); } } return 0;}
阅读全文
0 0
- POJ 2115(线性同余方程)
- POJ 2115(解线性同余方程)
- poj 2115(线性同余方程。。。。。)
- poj 1061 (解线性同余方程)
- poj 1061 (解线性同余方程)
- poj 1061(线性同余方程。。。。)
- POJ 2115 扩展欧几里德解线性同余方程
- poj 2115 C Looooops(解线性同余方程)
- POJ 2115 C Looooops(一元线性同余方程)
- 解 线性同余方程
- 线性同余方程:poj 2115 C Looooops
- POJ 2115-C Looooops(基础一元线性同余方程)
- POJ 2115-C Looooops(基础一元线性同余方程)
- POJ 2115 C Looooops (线性同余方程)
- POJ 2115 H - C Looooops(一元线性同余方程)
- POJ 2947 Widget Factory 高斯消元 解线性同余方程
- POJ 2657 Comfort(一元线性同余方程)
- poj 2115 同余方程
- 03-JDBC操作java语言数据库
- docker Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon runn
- 内存地址与寻址
- 迭代器模式
- postMessage 跨文档消息传递
- POJ 2115(解线性同余方程)
- EditText光标不显示问题
- 实验五:用callback增强链表模块来实现命令行菜单小程序V2.8
- @Transactional事务不起作用的解决
- 读《中国文脉》有感
- 算法:输入一个四位数,然后分别输出这个四位数的每一位数字
- 转,面试总结
- java.util.concurrent 之 可重入锁ReentrantLock
- python基础(二)关于编码和字符串操作etc