http://www.luogu.org/problem/show?pid=1029
由lcm(a,b)=a*b/gcd(a,b)得 a*b = lcm(a,b)*gcd(a,b)
设给出两个整数为x,y,要求的两个数为R,Q 原式变为R*Q=x*y
变形得 Q = (x*y)/R;
然后枚举R,就可以求出Q,继而得出解
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int x,y;
int gcd(int a, int b)
{
int a1 = a, b1 = b;
if (a1<b1) swap(a1,b1);
while (b1!=0)
{
int c = a1 % b1;
a1 = b1;
b1 = c;
}
return a1;
}
int main()
{
scanf("%d%d", &x ,&y);
int tot = x*y;
int k = 0;
for (int i=1;i<=round(sqrt(tot));i++)
{
if (tot % i==0)
{
if (gcd(tot/i, i)==x) k+=2;
}
}
printf("%d\n", k);
return 0;
}