[luoguP1516] 青蛙的约会(扩展欧几里得)
2024-09-30 21:22:03
对于数论只会gcd的我,也要下定决心补数论了
列出方程
- (x + t * m) % l = (y + t * n) % l
那么假设 这两个式子之间相差 num 个 l,即为
- x + t * m = y + t * n + num * l
经过化简得
- (n - m) * t + l * num = x - y
那么可以用扩展欧几里得求出结果
——代码
#include <cstdio>
#define LL long long inline void exgcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(!b) d = a, x = 1, y = 0;
else exgcd(b, a % b, d, y, x), y -= x * (a / b);
} int main()
{
LL x, y, m, n, l, d, t, num;
scanf("%lld %lld %lld %lld %lld", &x, &y, &m, &n, &l);
if(n - m < 0) x ^= y ^= x ^= y, n ^= m ^= n ^= m;
exgcd(n - m, l, d, t, num);
if((x - y) % d) puts("Impossible");
else l = l / d, printf("%lld\n", ((x - y) / d * t % l + l) % l);
return 0;
}
最新文章
- js jquery 页面加载初始化方法
- Git / 程序员需要知道的12个Git高级命令
- Echarts 地图控件tooltip多行显示
- ubuntu 16.04 小键盘数字键盘开机自动启动
- 一个简单且丑陋的js切换背景图片基础示例
- Android Density(密度)
- (转)smarty实现多级分类的方法
- web开发小白之路
- PHP环境部署问题集合
- Linux笔记(十一) - 文件系统管理
- struts2 之 struts2类型转换
- POJ3069(贪心+巧用优先队列)
- CSS3媒体查询(Media Queries)介绍
- android动画源码合集、动态主题框架、社交app源码等
- jQuery 选择器 prop() 和attr()
- NOI-OJ 1.13 ID:5 素数回文数的个数
- idea构建spark开发环境,并本地运行wordcount
- redis副本集
- SQL Server XML 查询
- forfiles命令详解
热门文章
- table样式测试总结tr td宽度分析
- bzoj4720: [Noip2016]换教室(期望dp)
- ACM_蛇形矩阵
- 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先
- error: no such device : 76de62ec-ac60-4c4d-bb Entering rescue mode .. grub resuce>;(系统硬盘驱动器MBR已损坏)问题解决办法(图文详解)
- android视频播放器系列(二)——VideoView
- 开发一款APP需要多少钱
- 使ThinkPHP(3.2.3)的分页类支持Bootstrap风格
- HDU_1556_线段树区间更新
- iOS,Core Animation--负责视图的复合功能