hdu1787-易做图 Again
非数组形式,用于大数据
[cpp]
#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 ;
}
#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 ;
}
补充:软件开发 , C++ ,