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 LCM of (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 the LCMcardinality 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 Cis its cardinality. These two numbers are separated by a single space.
12
24
101101291
12 8
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 Cis its cardinality. These two numbers are separated by a single space.
Sample Input
2
12
24
101101291
0
Output for Sample Input
2 212 8
24 11
101101291 5
对于n的每个素因子,均作为一个乘数时,和最小,须注意特殊情况如n=1以及n为素数幂。
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#define LL long long
using namespace std;
#define maxn 100005
LL prime[maxn],c;
LL v[maxn];
void p()
{
LL i,j,n=maxn,m;
c=0;
m=(LL)sqrt(n+0.5);
memset(v,0,sizeof(v));
for(i=2;i<=m;i++)
if(!v[i]){
for(j=i*i;j<=n;j+=i)
v[j]=1;
}
for(j=2;j<=n;j++){
if(!v[j]){
prime[c++]=j;
}
}
}
int main()
{
LL n,ans,temp;
int flag,ca=1;
p();
while(~scanf("%lld",&n),n){
ans=flag=0;
if(n==1) ans=2;
else{
for(int i=0;n>1&&i<c;i++){
if(n%prime[i]==0){
flag++;
temp=prime[i];
n/=prime[i];
while(n%prime[i]==0){
n/=prime[i];
temp*=prime[i];
}
ans+=temp;
}
}
if(flag==1) ans++;
else if(flag==0){
ans=n+1;
}
}
printf("Case %d: %lld\n",ca++,ans);
}
return 0;
}