poj1061 2010.2.17
2016-02-05 14:23
302 查看
poj1061 2010.2.17
#include <iostream> using namespace std; __int64 x,y,m,n,l; __int64 modularLinearEquation(__int64 a,__int64 b,__int64 n); __int64 extEuclid(__int64 a, __int64 b); int main(void) { __int64 s; scanf("%I64d",&x); scanf("%I64d",&y); scanf("%I64d",&m); scanf("%I64d",&n); scanf("%I64d",&l); s=modularLinearEquation((n-m+l)%l,(x-y+l)%l,l); if (s<0) printf("Impossible\n"); else printf("%I64d\n",s); return 0; } __int64 modularLinearEquation(__int64 a,__int64 b,__int64 n) { __int64 d,result; result=-1; d=extEuclid(a,n); if (b%d!=0) return result; x=x*(b/d); x=(x%(n/d)+n/d)%(n/d); result=x; return result; } __int64 extEuclid(__int64 a, __int64 b) { __int64 r,t; if (b==0) { x=1; y=0; return a; } r=extEuclid(b,a%b); t=x; x=y; y=t-a/b*y; return r; }
相关文章推荐
- poj1503 2010.2.17
- POJ 2482 线段树+离散化
- [转] 编程语言解惑:学.Net还是学Java
- js前端分页
- freemarker中include与import的区别
- 一个单元测试问题的解决
- 计算机网络的结构组成
- PAT1003.我要通过!
- poj1459 2010.2.17
- poj1047 2010.2.17
- [转] MySQL5绿色版安装教程
- include<>与include""的区别
- 类
- Java程序员需要了解的8个开发工具
- 深度优先搜索的学习
- poj1419——Graph Coloring(dfs)
- [转] 转载:一条网线,不用路由器,多台笔记本电脑共享上网
- 深入浅出Windows BATCH
- HDU 1028 (dp)
- poj1273 2010.2.17