/**
题意:(x,y)有两种走法,第一种(x,y+lcm(x,y)) 和 第二种(x+lcm(x,y),y);
现在给你 终点 (x,y) 则有几种可能的起点
现在我们假设起点为( x0,y0 ),则 x0 == x 且 y0 == y 是一个合法的起点
于是再往上推
d = gcd(x0,y0);
x0 = k1*d; x1 = k2*d;
lcm(x0,y0) = k1*k2*d;
假设x < y : 一定是通过y的移动到达的(x,y);
x = x0 = k1*d; y = y0 + kcd(x0,yo) = k2*d+k1*k2*d;
x = k1*d
y = k2*(k1+1)*d
k1 与 k2互质, k1与k1+1互质
k1 与 k2*(k1+1)互质
gcd(x,y) = d = gcd(x0,y0);
y0 = k2*d = y/(k1*d+d)*d = y/(x+d)*d
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#define mem(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define LL long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define pi (acos(-1.0))
#define eps (1e-8)
using namespace std;
LL solve(LL a,LL b)
{
LL d = __gcd(a,b);
if(a > b) swap(a,b);
if(b % (a+d) == 0)
return 1+solve(a,b/(a+d)*d);
return 1;
}
int main()
{
int caset,t = 1;
scanf("%d",&caset);
while(caset--)
{
LL a,b;
scanf("%lld%lld",&a,&b);
printf("Case #%d: ",t++);
printf("%lld\n",solve(a,b));
}
return 0;
}
HDOJ5584 Lcm Walk 2015ICPC上海-L
最新推荐文章于 2018-10-01 21:15:54 发布