A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, thenumber of different integer pairs with LCM is equal to N can be called the LCM cardinality of thatnumber N. In this problem your job is to find out the LCM cardinality of a number.
题意:现在给你1个数字C,让你求有多少对的数字的最小公倍数数是C。
思路:由于数字的最小公倍数是C,那么他肯定是C的因子,
暴力求出所有C的因子,然后在一步一步进行比较,判断就行了。暴力。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n,cnt;
int num[100000];
void chuli(){
int sum=2;
cnt=0;
for(int i=2;i<=sqrt(n);i++)
if(n%i==0){
num[cnt++]=i;
if(i==n/i)continue;
num[cnt++]=n/i;
}
sum+=cnt;
for(int i=0;i<cnt;i++)
for(int j=i+1;j<cnt;j++)
if(num[i]*num[j]==__gcd(num[i],num[j])*n){
//printf("%d %d\n",num[i],num[j]);
sum++;}
printf("%d %d\n",n,sum);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==0) break;
if(n==1){
printf("1 1\n");
continue;
}
chuli();
}
return 0;
}