Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3284 Accepted Submission(s): 1350
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<stdio.h>
2 #include<string.h>
3 const int maxn=3000001;
4 __int64 phi[maxn];
5 int main()
6 {
7 int st,en,i,j;
8 for(i=1;i<maxn;i++)
9 phi[i]=i;
10 for(i=2;i<maxn;i+=2)
11 phi[i]/=2;
12 for(i=3;i<maxn;i+=2)
13 {
14 if(phi[i]==i)
15 {
16 for(j=i;j<maxn;j+=i)
17 {
18 phi[j]=phi[j]/i*(i-1); /*from left to right*/
19 }
20 }
21 }
22 while(scanf("%d%d",&st,&en)!=EOF)
23 {
24
25 __int64 ans=0;
26 for(i=st;i<=en;i++)
27 {
28 ans+=phi[i];
29 }
30 printf("%I64d\n",ans);
31 }
32
33 return 0;
34 }
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有