LCM Cardinality 暴力

时间:2023-04-02 17:41:20
LCM Cardinality

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

Problem F
LCM Cardinality
Input: Standard Input

Output: Standard Output

Time Limit: 2 Seconds

A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCMof (1, 12)(2, 12)(3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called theLCM cardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.

Input

The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.

Output

For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a single space.

Sample Input                             Output for Sample Input

2 
12 
24 
101101291 
0 

2 2

12 8

24 11

101101291 5

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int gcd(int x,int y)
{
if(y==)return x;
return gcd(y,x%y);
}
int lcm(int x,int y)
{
return x/gcd(x,y)*y;
}
long long c[];
int main()
{
int n,nu,i,j,size,ans;
while(scanf("%d",&n),n)
{
ans=nu=;
size=sqrt(n+0.5);
for(i=; i<=size; i++)
{
if(n%i==)
{
c[nu++]=i;
if(i*i!=n)
c[nu++]=n/i;
}
}
for(i=; i<nu; i++)
{
for(j=i; j<nu; j++)
if(lcm(c[i],c[j])==n)ans++;
}
cout<<n<<" "<<ans<<endl;
}
}