AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

AcWing 222. 青蛙的约会

作者: 作者的头像   wyc1996 ,  2021-01-13 09:36:16 ,  阅读 10


1


(1)系数应当进行乘以相应的倍数
(2)通解的形式为:x+k(b/d)

#include<iostream>

using namespace std;
typedef long long LL;

int exgcd(int a,int b,LL &x,LL &y)
{
    if(!b){
        x=1,y=0;
        return a;
    }
    int d=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}

int main()
{
    int a,b,m,n,L;
    cin>>a>>b>>m>>n>>L;
    LL x=0,y=0;
    int d=exgcd(m-n,L,x,y);
    if((b-a)%d)cout<<"Impossible"<<endl;
    else {
        x*=(b-a)/d;
        LL t=abs(L/d);
        cout<<(x%t+t)%t<<endl;
    }
    return 0;
}

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息