HDU 2824 The Euler function 欧拉函数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2824
题目描述: 求欧拉函数?
解题思路: 欧拉函数
代码:
#include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #include <cmath> #include <algorithm> #include <stack> #include <deque> #include <map> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define mem0(a) memset(a,0,sizeof(a)) #define sca(x) scanf("%d",&x) #define de printf("=======\n") typedef long long ll; using namespace std; const int maxn = 3e6+10; const int n = 3e6; int phi[maxn]; void init() { for( int i = 2; i <= n; i++ ) { phi[i] = 0; } phi[1] = 1; for( int i = 2; i <= n; i++ ) { if( !phi[i] ) { for( int j = i; j <= n; j+=i ) { if( !phi[j] ) phi[j] = j; phi[j] = phi[j] / i * (i-1); } } } // for( int i = 1; i <= 10; i++ ) { // cout << phi[i] << " "; // } // cout << endl; } int main() { init(); int a, b; while( scanf( "%d%d", &a, &b ) == 2 ) { ll ans = 0; for( int i = a; i <= b; i++ ) { ans += phi[i]; } printf( "%lld\n", ans ); } return 0; }
思考: 这个题单里怎么会有这么裸的题......我一开始还以为复杂度不够呢.....水水更健康
posted on 2017-08-30 21:31 FriskyPuppy 阅读(134) 评论(0) 编辑 收藏 举报