0
点赞
收藏
分享

微信扫一扫

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

小飞侠熙熙 2022-09-16 阅读 149

The Euler function

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

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 ​​

 

 

Recommend

 

欧拉函数挺有用的似乎,欧拉函数表和朴素筛法是有着异曲同工之妙的

1 #include "bits/stdc++.h"
2 using namespace std;
3 typedef long long LL;
4 const int MAX=3e6+5;
5 int phi[MAX];
6 void eular(){
7 int i,j;
8 for (i=1;i<MAX;i++) phi[i]=i;
9 for (i=2;i<MAX;i+=2) phi[i]/=2;
10 for (i=3;i<MAX;i+=2){
11 if (phi[i]==i)
12 for (j=i;j<MAX;j+=i)
13 phi[j]=phi[j]/i*(i-1);
14 }
15 }
16 int main(){
17 freopen ("euler.in","r",stdin);
18 freopen ("euler.out","w",stdout);
19 int i,j;
20 eular();
21 LL x,y,ans;
22 while (~scanf("%lld%lld",&x,&y)){
23 for (i=x,ans=0;i<=y;i++) ans+=(LL)phi[i];
24 printf("%lld\n",ans);
25 }
26 return 0;
27

 

举报

相关推荐

0 条评论