http://acm.hdu.edu.cn/showproblem.php?pid=1787
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std ;
#define INT __int64
int enlerfun( int n )
{
int tempnum = 1 ;
int i ;
for( i = 2 ; i * i <= n ; ++i )
{
if( n % i == 0 )
{
n /= i ;
tempnum *= ( i - 1 ) ;
while( n % i == 0 )
{
n /= i ;
tempnum *= i ;
}
}
}
if( n > 1 )
tempnum *= ( n - 1 ) ;
return tempnum ;
}
int main()
{
int n ;
int count ;
while( ~scanf( "%d" , &n ) && n )
{
printf( "%d\n" , n - 1 - enlerfun( n ) ) ;
}
return 0 ;
}
本文提供了一道来自HDU在线评测系统的题目1787的解答思路及完整代码实现。该题涉及计算整数n的欧拉函数值,即小于等于n的正整数中与n互质的数量,并最终求得n减去其欧拉函数值的结果。
11万+

被折叠的 条评论
为什么被折叠?



