POJ2115 C Looooops 一元模线性方程
来源:互联网 发布:格瓦拉网络购票 编辑:程序博客网 时间:2024/05/24 05:46
/* 题目描述:给出程序段for(int i = A ; i!= B ; i+= C) statement ,给出A,B,C,k,已知该程序段的运算中出现 的数都是mod k之后的,问该程序段将被执行多少次结束,不会结束的话输出FOREVER 方法:由题意列出方程有A + Cx = B (mod k),变形Cx = B - A(mod k),要求该模线性方程的最小正整数解*/#pragma warning(disable:4786)#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<map>#include<set>#include<vector>#include<cmath>#include<string>#include<sstream>#define LL long long#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define mem(a,x) memset(a,x,sizeof(a))#define lson l,m,x<<1#define rson m+1,r,x<<1|1using namespace std;const int INF = 0x3f3f3f3f;const int mod = 1e9 + 7;const double PI = acos(-1.0);const double eps=1e-8;LL ex_gcd(LL a , LL b , LL &x , LL &y ){ if(b==0){ x = 1; y = 0; return a; } LL d = ex_gcd(b , a% b , y , x); y = y - a/b * x; return d;}LL linearmod(LL a , LL b , LL c) //求解ax=b (mod c)的最小正整数解{ LL x , y; LL d = ex_gcd(a , c , x , y); if(b%d) return -1; x = b / d * x ; LL m = c / d; return (x % m + m)% m;}int main(){ LL a , b , c ; int k; while(scanf("%lld%lld%lld%d",&a , &b , &c , &k)==4 ){ if(!a && !b && !c && !k) break; LL real_mod = 1LL << k; LL ans = linearmod(c ,b - a , real_mod); if(ans == -1) printf("FOREVER\n"); else printf("%lld\n" , ans ); } return 0;}
0 0
- POJ2115 C Looooops 一元模线性方程
- C Looooops poj2115 (扩展欧几里得+模线性方程)
- poj2115——C Looooops(数论,解模线性方程)
- POJ2115 C Looooops ——模线性方程(扩展gcd)
- C Looooops--模线性方程
- POJ2115 C Looooops 解一元线性同余方程
- 欧几里德 poj2115 C Looooops
- POJ2115 C Looooops
- POJ2115-C Looooops
- [POJ2115] C Looooops
- #POJ2115# C Looooops
- POJ2115-C Looooops
- POJ2115 C Looooops
- Poj 2115 C Looooops (模线性方程)
- poj 2115 C Looooops(模线性方程)
- poj 2115 C Looooops (解模线性方程)
- POJ 2115 C Looooops (模线性方程)
- poj2115--C Looooops(扩展gcd)
- iOS 调用系统通讯录 获取联系人信息
- 在Android Studio中直接编译C/C++文件
- Android开发_Sharedpreferences_存储数据使用方法_完整Demo_AndroidStudio
- 关于static问题的分析
- tomcat无法关闭问题
- POJ2115 C Looooops 一元模线性方程
- HDU 1272 小希的迷宫 (kruskal)
- Tomcat发布多个项目抛出异常
- Mercurial ---hgignore
- LibVLC自定义插件目录,获取FPS方法
- liferay学习4--helloLiferay例子
- 1.工具类
- Android读取assets目录下文件数据内容
- javacript中的闭包