题目分析:
设时间为t,则两个青蛙的位置分别为(x+mt)mod L、(y+nt) mod L,相遇即是(x+mt)%L=(y+nt)%L,即(m-n)*t+k*L=y-x。
OK,现在已经符合ax+by=c的方程了,设a=m-n,b=L,c=y-x,然后套用模板求出特解t的值,注意t>0,所以要用通解公式得出最小正整数(为啥刚开始我就没想到这一点呢)。最后注意用long long~
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
ll extended_gcd(ll a,ll b,ll &x,ll &y)
{
ll r,t;
if(!b)
{
x=1;
y=0;
return a;
}
r=extended_gcd(b,a%b,x,y);
t=x;
x=y;
y=t-a/b*y;
return r;