2022春每日一题:Day 25
2024-10-20 11:59:35
题目:青蛙的约会
读完题,显然可以的到下同余方程: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;
}
最新文章
- 让PictureBox支持URL显示图片
- android需知小细节
- What is GSLB
- Markdown入门教程
- jq图片切换特效
- 【xml 报错】xml编译错误
- volley源代码解析(七)--终于目的之Response&;lt;T&;gt;
- java中的特殊字符集合
- angular学习笔记 父子组件传值
- Python OptionParser 使用详解(转载)
- python 之 函数的参数
- 模拟php curl向远程服务器上传文件
- External RNA Controls Consortium (ERCC)
- P2048 [NOI2010]超级钢琴 (RMQ,堆)
- docker使用笔记1
- 全国省市区数据库SQL(有可能不是最新的)
- TensorFlow Python3.7环境下的源码编译(一)环境准备
- 两类for循环
- Spring框架中的单例Beans是线程安全的么
- Python初学者第四天 二进制运转换