标签:style blog http io color ar os for sp
#include <cstdio> #include <cstring> using namespace std; #define CLR( a, b ) memset( a, b, sizeof(a) ) #define MAXN 1010 int phi[ MAXN ], farey[ MAXN ], n, t; void get_euler() //打欧拉函数表 { CLR( phi, 0 ); phi[1] = 1; for( int i = 2; i < MAXN; ++i ) { if( !phi[i] ) { for( int j = i; j < MAXN; j+=i ) { if( !phi[j] ) phi[j] = j; phi[j] = phi[j] / i * ( i - 1 ); } } } } void cal() { farey[1] = 1 + phi[1]; //根据farey数列和欧拉函数的关系 初始化法雷级数F[1]为2 for( int i = 2; i <= MAXN; ++i ) farey[i] = phi[i] + farey[i-1]; } int main() { get_euler(); cal(); scanf( "%d", &t ); for( int i = 1; i <= t; ++i ) { scanf( "%d", &n ); printf( "%d %d %d\n", i, n, farey[n] * 2 - 1 ); } return 0; }
POJ 3090 Visible Lattice Points ( 法雷数列 + 欧拉函数 )
标签:style blog http io color ar os for sp
原文地址:http://www.cnblogs.com/BigBallon/p/4074046.html