POJ 1061 青蛙的约会(扩展欧几里德)
2015-08-16 10:34
363 查看
题目链接:http://poj.org/problem?id=1061
#include<cstdio> #include<iostream> #include<sstream> #include<cstdlib> #include<cstring> #include<string> #include<climits> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<set> #include<map> using namespace std; long long t, p, c; void ou(int a, int b) { if(b == 0) { t = 1; p = 0; c = a; } else { ou(b, a%b); int temp = t; t = p; p = temp - a/b*p; } } int main() { int i, j, flag = 0, d, a, b; long long x, y, m, n, l; scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l); if(n == m) flag= 1; else { a = n-m; d = x-y; b = l; ou(a, b); if(d % c !=0) flag= 1; } if(flag) printf("Impossible\n"); else { b = b / c; d = d / c; long long v = d * t; printf("%d\n",(v%b+b)%b); } return 0; }
相关文章推荐
- JVM-垃圾收集器与内存分配策略
- Qt5该插件机制(2)--QxxxFactory类和QFactoryLoader类别
- dp概括(1)
- poj 2481 cows 树状数组
- iOS面试关于http知识点basic-01-http
- 数据结构读书笔记2
- 倒计时js代码
- Eclipse 常用正则表达式
- powerdesigner 创建物理结构视图
- [NOIP2000]单词接龙
- 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis
- ecshop如何在商品详细页显示已售数量和评论数量
- HDU 1671 — Phone List
- Codeforces 148 D Bag of mice
- 如何打开Galaxy S4的USB调试
- 内核内存分配--关于高内存
- 设计模式原则
- 贪心算法之Elevator Stopping Plan
- 大型网站架构演变过程、高并发服务器架构
- Codeforces Round #316 (Div. 2)E. Pig and Palindromes(dp好题)