题解:

要求s+px=t+qx (mod L)

移项 (p-q)x=t-s (mod L)

等价于 (p-q)x+Ly=t-s

即ax+by=c的方程最小非负根

exGcd后乘个C

 #include<cstdio>
typedef long long ll;
using namespace std;
ll s,t,p,q,L;
ll gcd (ll x,ll y)
{
return y==?x:gcd(y,x%y);
}
ll exGcd(ll a,ll b,ll &x,ll &y)
{
if (b==) return x=,y=,a;
ll r=exGcd(b,a%b,y,x);
y-=(a/b)*x;
return r;
}
int main()
{
scanf("%lld%lld%lld%lld%lld",&s,&t,&p,&q,&L);
ll a=(p-q+L)%L,b=L,c=(t-s+L)%L,x,y,G=gcd(a,b);
if (c%G!=)
{
puts("Impossible");
return ;
}
a/=G,b/=G,c/=G;
exGcd(a,b,x,y);
x=(x%b+b)%b;
x=x*c%b;
printf("%lld\n",x);
return ;
}

POJ 1061 青蛙的约会 | 同余方程和exGcd的更多相关文章

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

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

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

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

  3. POJ.1061 青蛙的约会 (拓展欧几里得)

    POJ.1061 青蛙的约会 (拓展欧几里得) 题意分析 我们设两只小青蛙每只都跳了X次,由于他们相遇,可以得出他们同余,则有: 代码总览 #include <iostream> #inc ...

  4. POJ 1061 青蛙的约会(拓展欧几里得求同余方程,解ax+by=c)

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

  5. poj 1061青蛙的约会

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 90083   Accepted: 16257 Descripti ...

  6. poj 1061 青蛙的约会 (扩展欧几里得模板)

    青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status ...

  7. POJ 1061 青蛙的约会 题解

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

  8. POJ 1061 青蛙的约会(扩展GCD求模线性方程)

    题目地址:POJ 1061 扩展GCD好难懂.. 看了半天.最终把证明什么的都看明确了. .推荐一篇博客吧(戳这里),讲的真心不错.. 直接上代码: #include <iostream> ...

  9. POJ——1061 青蛙的约会

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

随机推荐

  1. 微信小程序日期选择器

    /* JS代码部分 */ const date = new Date() const years = [] const months = [] const days = [] const hours ...

  2. BZOJ1854: [Scoi2010]游戏(二分图匹配)

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

  3. bootloader svc 模式

    bootloader 和操作系统都是工作在svc模式下 /* * set the cpu to SVC32 mode */ mrs r0,cpsr bic r0,r0,#0x1f orr r0,r0, ...

  4. JavaScript---ECMA对象

    1.对象的概念及分类 1.1 ECMAScript中没有类,但定义了“对象”,逻辑上等价于其他程序设计语言中的类. var o = new Object(); 1.2 本地对象(native obje ...

  5. fastadmin 后台管理框架使用技巧(持续更新中)

    fastadmin 后台管理框架使用技巧(持续更新中) FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架,具体介绍,请查看文档,文档地址为:https://doc. ...

  6. php 变量的8类类型

    整形,布尔,浮点形,字符串,数组,资源,对象和null php数据类型之查看和判断数据类型 php数据类型之自动转换和强制转换

  7. python搭建友盟以及个推推送web服务器

    一.友盟客户端demo: 由于SDK原因,新版Android Studio的Android API 28 Platform无法同步新建项目, 所以我最终选择下载android-studio-bundl ...

  8. POJ:2385-Apple Catching(dp经典题)

    Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14311 Accepted: 7000 Descr ...

  9. 13-在Core Mvc中使用Options

    配制文件appsettings和Classes来自12节 在HomeController增加如下代码,使用IOption方式进行注入 public class HomeController : Con ...

  10. 笔记-twisted

    笔记-twisted 1.      简介 Twisted is an event-driven networking engine written in Python and licensed un ...