传送门

对于数论只会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;
}

  

最新文章

  1. js jquery 页面加载初始化方法
  2. Git / 程序员需要知道的12个Git高级命令
  3. Echarts 地图控件tooltip多行显示
  4. ubuntu 16.04 小键盘数字键盘开机自动启动
  5. 一个简单且丑陋的js切换背景图片基础示例
  6. Android Density(密度)
  7. (转)smarty实现多级分类的方法
  8. web开发小白之路
  9. PHP环境部署问题集合
  10. Linux笔记(十一) - 文件系统管理
  11. struts2 之 struts2类型转换
  12. POJ3069(贪心+巧用优先队列)
  13. CSS3媒体查询(Media Queries)介绍
  14. android动画源码合集、动态主题框架、社交app源码等
  15. jQuery 选择器 prop() 和attr()
  16. NOI-OJ 1.13 ID:5 素数回文数的个数
  17. idea构建spark开发环境,并本地运行wordcount
  18. redis副本集
  19. SQL Server XML 查询
  20. forfiles命令详解

热门文章

  1. table样式测试总结tr td宽度分析
  2. bzoj4720: [Noip2016]换教室(期望dp)
  3. ACM_蛇形矩阵
  4. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先
  5. error: no such device : 76de62ec-ac60-4c4d-bb Entering rescue mode .. grub resuce&gt;(系统硬盘驱动器MBR已损坏)问题解决办法(图文详解)
  6. android视频播放器系列(二)——VideoView
  7. 开发一款APP需要多少钱
  8. 使ThinkPHP(3.2.3)的分页类支持Bootstrap风格
  9. HDU_1556_线段树区间更新
  10. iOS,Core Animation--负责视图的复合功能