The Euler function[HDU2824]

The Euler function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6018 Accepted Submission(s): 2539

Problem Description
The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+....+ (b)

Input
There are several test cases. Each line has two integers a, b (2<a<b<3000000).

Output
Output the result of (a)+ (a+1)+....+ (b)

Sample Input
3 100

Sample Output
3042

3000000的数据范围,没想到是直接加的......贡献一次MLE。

#include <stdio.h>
#include <string.h>
int euler[3000010];
void Euler_Sieve_Method(int * euler, int n) {
    euler[1] = 1;
    for (int i = 2; i < n; i++) {
        euler[i] = i;
    }
    for (int i = 2; i < n; i++) {
        if (euler[i] == i) {
            for (int j = i; j < n; j += i) {
                euler[j] = euler[j] / i * (i - 1);
            }
        }
    }
}
int main() {
    Euler_Sieve_Method(euler, 3000005);
    int a, b;
    while (scanf("%d%d", &a, &b) != EOF) {
        __int64 s = 0;
        for (int i = a; i <= b; i++) {
            s += euler[i];
        }
        printf("%I64d\n", s);
    }
    return 0;
}

时间: 2024-10-14 00:17:28

The Euler function[HDU2824]的相关文章

hdu2824 The Euler function(欧拉函数个数)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数性质: 1:(百科):http://baike.baidu.com/link?url=r-yneKCCyS9N6bhbQCqiZX0V2OCYq9r7iHSzHTSs03H7qRvu1OfUzlOxfVEs2PmR 2:http://www.cppblog.com/doer-xee/archive/2009

hdu2824 The Euler function O(n)求欧拉函数

hdu2824 The Euler function O(n)求欧拉函数 1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std ; 4 5 const int N = 3000011 ; 6 int l,r ; 7 int prime[ 300011 ],phi[N] ; 8 ll sum ; 9 bool f[N] ; 10 11 inline void Euler_init(int NN) 12 {

hdu-2824 The Euler function(欧拉函数)

题目链接: The Euler function Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4987    Accepted Submission(s): 2098 Problem Description The Euler function phi is an important kind of function in numb

HDU 2824 The Euler function

The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3789    Accepted Submission(s): 1569 Problem Description The Euler function phi is an important kind of function in number theo

HDU 2824 The Euler function 题解

求区间的euler数值,自然使用筛子法了. Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful character

The Euler function(线性筛欧拉函数)

/* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体证明看po主的博客 ^0^ #超时:这里直接用欧拉函数暴力搞还是不可以的,用到线性筛欧拉函数,这里总和爆int,要用long long */ #include<bits/stdc++.h> #define ll long long using namespace std; /***********

hdu 2824 The Euler function 欧拉函数打表

The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are sm

杭电2824--The Euler function(欧拉函数)

The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4559    Accepted Submission(s): 1902 Problem Description The Euler function phi is an important kind of function in number theo

hdoj 2824 The Euler function

The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4548    Accepted Submission(s): 1895 Problem Description The Euler function phi is an important kind of function in number the