POJ1061青蛙的约会(扩展欧几里得)
2024-09-23 23:55:09
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <stack>
#include <set>
#include <queue>
#define MAX(a,b) (a) > (b)? (a):(b)
#define MIN(a,b) (a) < (b)? (a):(b)
#define mem(a) memset(a,0,sizeof(a))
#define INF 1000000007
#define MAXN 20005
using namespace std; __int64 GCD(__int64 a,__int64 b)
{
return a%b==?b:GCD(b,a%b);
} void gcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
if(!b){x=;y=;}
else{gcd(b,a%b,y,x); y-=x*(a/b);}
} int main()
{
__int64 X,Y,M,N,L;
while(~scanf("%I64d %I64d %I64d %I64d %I64d",&X,&Y,&M,&N,&L))
{
__int64 a = (N-M), b = L, c = (X-Y);
__int64 g = GCD(a,b);
if(c%g){ printf("Impossible\n"); continue;}
__int64 x, y;
gcd(a, b, x, y);
x*=(c/g);
if(x>)x%=(b/g);
else x=x%(b/g)+(b/g);
printf("%I64d\n",x);
}
return ;
}
最新文章
- 3D游戏编程大师技巧──2D引擎的编译问题
- [转]彻底征服 Spring AOP 之 实战篇
- 转载:Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04
- rabbitMQ学习(一)
- 在sublime中使用less
- Rhel6-mailsystem配置文档
- php截取字符串,无乱码
- 图解linux下top命令的使用
- SNMP配置和常用命令OID(转)
- 关于Asp.net超时,延长读取sql server数据库的超时时间!(已解决)
- LANMP一键安装包 版本服务任你选 可安装单一服务
- layui动态设置checkbox选中状态
- 怎样下载youtube的字幕
- 6M - 循环多少次?
- 记录:一个SQL SERVER奇怪的问题。
- 关于C++中的friend友元函数的总结
- curl以cookie的方式登录
- 学习计划 mysql 整数类型后面的数字,是什么意思?
- MySQL函数GROUP_CONCAT() 实现多条数据合并
- IOC给程序带来的好处
热门文章
- bzoj4080
- tomcat 默认项目设置
- LeetCode Swap Nodes in Pairs 交换结点对(单链表)
- 【转】linux驱动开发的经典书籍
- POJ 2159 Ancient Cipher
- MyBatis 入门到精通(三) 高级结果映射
- mybatis实战教程(mybatis in action)之九:mybatis 代码生成工具的使用
- TOAD FOR MYSQL 进行数据插入时乱码的解决办法---MariaDB 5.5
- <;转>;Python学习推荐
- 给Webkit内核的浏览器控件增加互交功能