zoukankan      html  css  js  c++  java
  • 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("=======
    ")
    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
    ", ans );
        }
        return 0;
    }
    View Code

      思考: 这个题单里怎么会有这么裸的题......我一开始还以为复杂度不够呢.....水水更健康

  • 相关阅读:
    接口和抽象的区别
    继承-子父类中成员方法特点
    基本类型和引用类型作为参数传递
    大三寒假生活6
    大三寒假生活5
    大三寒假生活4
    大三寒假生活3
    大三寒假生活2
    大三寒假生活指导
    ajax实现文本框的联想功能
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7455393.html
Copyright © 2011-2022 走看看