LuoguP1516 青蛙的约会 (Exgcd)
#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)的更多相关文章
- POJ 1061 - 青蛙的约会 - [exgcd求解一元线性同余方程]
先上干货: 定理1: 如果d = gcd(a,b),则必能找到正的或负的整数k和l,使ax + by = d. (参考exgcd:http://www.cnblogs.com/dilthey/p/68 ...
- POJ1061 青蛙的约会 exgcd
这个题虽然很简单,但是有一个比较坑的地方,就是gcd不一定是1,有可能是别的数.所以不能return 1,而是return a; 题干: Description 两只青蛙在网上相识了,它们聊得很开心, ...
- LuoGuP1516 青蛙的约会 + 同余方程 拓展欧几里得
题意:有两只青蛙,在一个圆上顺时针跳,问最少的相遇时间. 这个是同余方程的思路.可列出方程:(m-n)* X% L = y-x(mod L) 简化为 a * x = b (mod L) (1 ...
- [luoguP1516] 青蛙的约会(扩展欧几里得)
传送门 对于数论只会gcd的我,也要下定决心补数论了 列出方程 (x + t * m) % l = (y + t * n) % l 那么假设 这两个式子之间相差 num 个 l,即为 x + t * ...
- 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_ ...
- POJ1061青蛙的约会[扩展欧几里得]
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108911 Accepted: 21866 Descript ...
- poj 1061 青蛙的约会 拓展欧几里得模板
// poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
- BZOJ-1477 青蛙的约会 拓展欧几里德
充权限之前做的...才来交 1477: 青蛙的约会 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 369 Solved: 233 [Submit][Sta ...
随机推荐
- Mac远程windows工具
现在很多小伙伴都是使用MAC系统,但在工作中或多或少会遇到需要远程windows的情况,今天给大家安利一款软件,让你轻轻松松远程windows Microsoft Remote Desktop Mic ...
- 使用多线程提高REST服务器性能
异步处理REST服务 1.使用Runnable异步处理Rest服务 释放主线程,启用副线程进行处理,副线程处理完成后直接返回请求 主要代码 import java.util.concurrent.Ca ...
- VB.net使用Microsoft.Office.Interop.Excel对Excel进行简单的读取和写入
环境:Visual Stadio 2017 .NET Framework 4.6.1 1.直接进入正题,新建一个控制台程序,右键引用-管理Nuget程序包,搜索Microsoft.Office.In ...
- [USACO16JAN]Angry Cows G 解题报告
一图流 参考代码: #include<bits/stdc++.h> #define ll long long #define db double #define filein(a) fre ...
- 服务器安装mysql遇到的坑
服务器安装mysql遇到的坑 一.CentOS7安装MySQL 1.下载:MySQL官方的 Yum Repository wget -i -c http://dev.mysql.com/get/mys ...
- python中f'{}'用法
python3.6增加的方法,字符串定义以f开头,可以使用{}包裹变量,方便字符串的定义. 有些时候很懒,碰到写的比较清晰的就直接搬运:https://blog.csdn.net/weixin_387 ...
- 入坑KeePass(四)KeePass通过坚果云WebDav同步方法
参考博客:什么值得买平台-Keepass+坚果云:多平台密码无缝同步 .1.在坚果云上创建一个同步专用的文件夹(建议勾上"默认不同步到电脑"选项) 创建之后可以把刚才创建的数据库文 ...
- 最简单的离散概率分布,伯努利分布 《考研概率论学习之我见》 -by zobol
上文讲了离散型随机变量的分布,我们从最简单的离散型分布伯努利分布讲起,伯努利分布很简单,但是在现实生活中使用的很频繁.很多从事体力工作的人,在生活中也是经常自觉地"发现"伯努利分布 ...
- 探索链路追踪在.NET6工业物联网项目的应用
ExploringIoTDistributedTracingNet6 如果觉得有用,请留言学到了. 已经会了的老哥,请留言就这? 可能遇到的问题 工业物联网项目自上而下一般分为ERP.Mes.SCAD ...
- Javaweb-Servlet学习
1.Servlet简介 Servlet就是sun公司开发动态web的一门技术 Sun在这些API中提供一个借口叫做:Servlet,如果你想开发一个Servlet程序,只需要完成两个小步骤: 编写一个 ...