#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b)) #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif
using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; #define int long long
inline int Gcd(int a, int b){
while(b ^= a ^= b ^= a %= b);
return a;
// if(!b) return a;
// return Gcd(b, a % b);
}
inline void Exgcd(int a, int b, int &x, int &y){
if(!b)
x = 1, y = 0;
else
Exgcd(b, a % b, y, x), y -= x * (a / b);
}
#undef int
int main(){
#define int long long
int a, b, m, n, L;
io >> a >> b >> m >> n >> L;
int A = n - m, B = L, C = a - b;
if(A < 0){
A = -A, C = -C;
}
int r = Gcd(A, B);
if(C % r){
printf("Impossible");
return 0;
}
A /= r, B /= r, C /= r;
//D_e(B);
int x, y;
Exgcd(A, B, x, y); // cout << x * C << endl;
// cout << x * C % B << endl;
// cout << x * C % B + B << endl;
printf("%lld", (x * C % B + B) % B); return 0;
}
/*
(n - m) * x + L * y = a - b A = n - m
B = L
C = A - B
*/

LuoguP1516 青蛙的约会 (Exgcd)的更多相关文章

  1. POJ 1061 - 青蛙的约会 - [exgcd求解一元线性同余方程]

    先上干货: 定理1: 如果d = gcd(a,b),则必能找到正的或负的整数k和l,使ax + by = d. (参考exgcd:http://www.cnblogs.com/dilthey/p/68 ...

  2. POJ1061 青蛙的约会 exgcd

    这个题虽然很简单,但是有一个比较坑的地方,就是gcd不一定是1,有可能是别的数.所以不能return 1,而是return a; 题干: Description 两只青蛙在网上相识了,它们聊得很开心, ...

  3. LuoGuP1516 青蛙的约会 + 同余方程 拓展欧几里得

    题意:有两只青蛙,在一个圆上顺时针跳,问最少的相遇时间.   这个是同余方程的思路.可列出方程:(m-n)* X% L = y-x(mod L) 简化为 a * x = b (mod L)    (1 ...

  4. [luoguP1516] 青蛙的约会(扩展欧几里得)

    传送门 对于数论只会gcd的我,也要下定决心补数论了 列出方程 (x + t * m) % l = (y + t * n) % l 那么假设 这两个式子之间相差 num 个 l,即为 x + t * ...

  5. P1516/bzoj1477 青蛙的约会

    青蛙的约会 exgcd 根据题意列出方程: 设所用时间为T,相差R圈时相遇 (x+T*m)-(y+T*n)=R*l 移项转换,得 T*(n-m)-R*l=x-y 设a=n-m,b=l,c=x-y,x_ ...

  6. POJ1061青蛙的约会[扩展欧几里得]

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 108911   Accepted: 21866 Descript ...

  7. poj 1061 青蛙的约会 拓展欧几里得模板

    // poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...

  8. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  9. BZOJ-1477 青蛙的约会 拓展欧几里德

    充权限之前做的...才来交 1477: 青蛙的约会 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 369 Solved: 233 [Submit][Sta ...

随机推荐

  1. java面试:关于public static void main(String[] args)是什么意思?

    它是作为JAVA中的主函数,所有java程序的运行起点就是这个方法,除了args这个名字可以不一样外,其他必须是这样. 主函数的一般写法如下: public static void main(Stri ...

  2. 渗透测试之常用的sql语句

    学习路漫漫,常用的sql语句给我们平常所运用的sql语句相差不多,用句土话讲:百变不离其中 注:网络安全时刻警醒,需要打靶的还需要建立自己的靶场,关注博主在以往博客中分享有多种创建靶场可参考 1.判断 ...

  3. Array 数组filter()方法,遍历数组返回符合条件的一个新数组

    <script> const arr = [ { id: 1, name: "aa", isDone: false }, { id: 2, name: "bb ...

  4. windows 2003系统安装

    一.使用workstation创建虚拟机 二.系统安装 点击"Enter" 点击"F8" 点击"Enter" 如下图所示: 点击" ...

  5. 隐私计算FATE-离线预测

    一.说明 Fate 的模型预测有 离线预测 和 在线预测 两种方式,两者的效果是一样的,主要是使用方式.适用场景.高可用.性能等方面有很大差别:本文分享使用 Fate 基于 纵向逻辑回归 算法训练出来 ...

  6. zabbix配置邮件报警

    1.yum源安装sendmail,sendmail-cf和mailx 2.关闭postfix,/etc/init.d/postfix stop chkconfig posfix off 3.启动sen ...

  7. idea中enter键不能换行

    idea中enter键不能换行 按enter键只能往下移动 如下图 解决办法: 方式一:按住window + Insert 方式二: 按住Fn + Insert 两种方式总有一种可以 之后就可以按en ...

  8. Nacos 的安装与服务的注册

    Nacos 的安装与服务的注册 我们都知道naocs是一个注册中心,那么注册中心是什么呢? 什么是注册中心? 它类似与一个中介角色(不收费的良心中介), 在微服务中起纽带的作用,它提供了服务和服务地址 ...

  9. 一文读懂数仓中的pg_stat

    摘要:GaussDB(DWS)在SQL执行过程中,会记录表增删改查相关的运行时统计信息,并在事务提交或回滚后记录到共享的内存中.这些信息可以通过 "pg_stat_all_tables视图& ...

  10. 如何借助Chrome Tool Dev 帮助前端开发

    11111111111111111111111111111111111111111111111111