码迷,mamicode.com
首页 > 其他好文 > 详细

[Luogu 1516] 青蛙的约会

时间:2018-10-25 21:12:39      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:oss   lib   can   org   scanf   scan   ssi   std   problem   

[Luogu 1516] 青蛙的约会

<题目链接>


两年前和初中那群队友一起当模拟做过,一起 TLE,一起骂过的题目;

一年前队友的博客上被当作例题,被我抄下来去操场都带着看的题目;

终于好好学习了 ExGCD,才发现是扩欧板子题并顺手切掉的题目…

雨中灯市欲眠,原已萧萧数年。
似有故人轻叩,又将旧题重写。
能否消得你一路而来的半生风雪?

#include <cstdio>
#include <cstdlib>

long long a, b, c, x, y, ans; 

void Read(void)
{
    long long x, y, m, n; 
    scanf("%lld %lld %lld %lld %lld", &x, &y, &m, &n, &b); 
    a = n - m; 
    c = x - y; 
    if(a < 0)
    {
        a = -a; 
        c = -c; 
    }
}

long long ExGCD(long long a, long long b, long long& x, long long& y)
{
    if(!b)
    {
        x = 1; 
        y = 0; 
        return a; 
    }
    long long t = ExGCD(b, a % b, y, x); 
    y -= a / b * x; 
    return t; 
}

int main(void)
{
    Read(); 
    ans = ExGCD(a, b, x, y); 
    if(c % ans)
        puts("Impossible"); 
    else
        printf("%lld\n", ((x * c / ans) % (b / ans) + (b / ans)) % (b / ans)); 
    return 0; 
}

谢谢阅读。

[Luogu 1516] 青蛙的约会

标签:oss   lib   can   org   scanf   scan   ssi   std   problem   

原文地址:https://www.cnblogs.com/Capella/p/9852791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!