题目:青蛙的约会

读完题,显然可以的到下同余方程:x+mk≡y+nk (mod L) 移项变成

(m-n)k+aL=y-x 只有k,L是未知的,而这题要求非负整数k的最小值,显然拓展欧几里得算法。

然后这题就做完了。

代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
int ex,ey,n,m,l,x,y;
int exgcd(int a,int b,int &x,int &y)
{
if(!b)
{
x=1,y=0;
return a;
}
int d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
signed main()
{
scanf("%lld %lld %lld %lld %lld",&ex,&ey,&m,&n,&l);
int d=exgcd(m-n,l,x,y);
if((ey-ex)%d!=0)
puts("Impossible");
else
{
x*=(ey-ex)/d;
int t=abs(l/d);
printf("%lld\n",(x%t+t)%t);
}
return 0;
}

最新文章

  1. 让PictureBox支持URL显示图片
  2. android需知小细节
  3. What is GSLB
  4. Markdown入门教程
  5. jq图片切换特效
  6. 【xml 报错】xml编译错误
  7. volley源代码解析(七)--终于目的之Response&amp;lt;T&amp;gt;
  8. java中的特殊字符集合
  9. angular学习笔记 父子组件传值
  10. Python OptionParser 使用详解(转载)
  11. python 之 函数的参数
  12. 模拟php curl向远程服务器上传文件
  13. External RNA Controls Consortium (ERCC)
  14. P2048 [NOI2010]超级钢琴 (RMQ,堆)
  15. docker使用笔记1
  16. 全国省市区数据库SQL(有可能不是最新的)
  17. TensorFlow Python3.7环境下的源码编译(一)环境准备
  18. 两类for循环
  19. Spring框架中的单例Beans是线程安全的么
  20. Python初学者第四天 二进制运转换

热门文章

  1. Linux之搭建FTP服务
  2. UTL_FILE 包使用介绍
  3. 巧用KingbaseES中的动态DDL
  4. oracle数据泵导入导出数据
  5. Linux_ps总结
  6. 使用sonarqube对java项目进行分析
  7. Logstash:导入zipcode CSV文件和Geo Search体验
  8. Elasticsearch:mapping定制
  9. nsis离开自定义页面保存设置
  10. 计算机网络(Learning Records)