http://acm.hdu.edu.cn/showproblem.php?pid=5584
LCM WalkTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2707 Accepted Submission(s): 1426 Problem Description A frog has just learned some number theory, and can't wait to show his ability to his girlfriend.
Input First line contains an integer T , which indicates the number of test cases.
Output For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1 and y is the number of possible starting grids.
|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 100005;
const int M = 10005;
const int inf = 1000000000;
const int mod = 10007;
int gcd(int x,int y)
{
if(x%y)
return gcd(y,x%y);
return y;
}
int main()
{
int t,k,c,p=1,x,y;
scanf("%d",&t);
while(t--)
{
c=1;
scanf("%d%d",&x,&y);
if(x>y)
swap(x,y);
k=gcd(x,y);
while(y%(x+k)==0)//不太懂这个地方
{
c++;
y=y/(x/k+1);
if(x>y)
swap(x,y);
k=gcd(x,y);
}
printf("Case #%d: %d\n",p++,c);
}
return 0;
}