UVA 10892 - LCM Cardinality(数学题)

时间:2021-01-25 07:01:32

题目链接

写写,就ok了。

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
#define MOD 1000000
#define LL long long
int prim[];
int o[];
int main()
{
int i,j,num = ,temp;
LL n;
for(i = ;i <= ;i ++)
{
if(!o[i])
{
for(j = i+i;j <= ;j += i)
o[j] = ;
}
}
for(i = ;i <= ;i ++)
{
if(!o[i])
prim[num++] = i;
}
while(cin>>n)
{
if(!n) break;
cout<<n<<" ";
LL ans = ;
for(i = ;i < num;i ++)
{
temp = ;
while(n%prim[i] == )
{
temp ++;
n /= prim[i];
}
ans *= ((temp+)*-);
}
if(n != )
ans *= ;
cout<<ans/ +<<endl;
}
return ;
}