HDU——T 2824 The Euler function

http://acm.hdu.edu.cn/showproblem.php?pid=2824

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7752    Accepted Submission(s): 3217

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

Source

2009 Multi-University Training Contest 1 - Host by TJU

欧拉函数表。前缀和

 1 #include <algorithm>
 2 #include <cstdio>
 3
 4 using namespace std;
 5
 6 #define LL long long
 7 const int N(3000233);
 8 LL a,b,phi[N];
 9
10 void All_phi()
11 {
12     for(int i=1;i<=N;i++)
13       phi[i]=i;
14     for(int i=2;i<=N;i++)
15       if(phi[i]==i)
16         for(int j=i;j<=N;j+=i)
17           phi[j]=phi[j]/i*(i-1);
18 }
19
20 int main()
21 {
22     All_phi();
23     for(int i=1;i<=N+1;i++) phi[i]=phi[i-1]+phi[i];
24     for(;scanf("%d%d",&a,&b)!=EOF;)
25         printf("%I64d\n",phi[b]-phi[a-1]);
26     return 0;
27 }
时间: 2024-07-29 21:22:26

HDU——T 2824 The Euler function的相关文章

欧拉函数 &amp; 【POJ】2478 Farey Sequence &amp; 【HDU】2824 The Euler function

http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函数,一是筛法,而是白书上的筛法. 首先看欧拉函数的性质: 欧拉函数是求小于n且和n互质(包括1)的正整数的个数.记为φ(n). 欧拉定理:若a与n互质,那么有a^φ(n) ≡ 1(mod n),经常用于求乘法逆元. 若p是一个质数,那么φ(p) = p-1,注意φ(1) = 1. 欧拉函数是积性函数

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

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 欧拉函数打表

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

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): 4507    Accepted Submission(s): 1872 Problem Description The Euler function phi is an important kind of function in number the

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

HDOJ The Euler function 2824【欧拉函数】

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

(hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory

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