前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ-----2824The Euler function

HDUOJ-----2824The Euler function

作者头像
Gxjun
发布2018-03-22 12:45:13
6100
发布2018-03-22 12:45:13
举报
文章被收录于专栏:mlml

The Euler function

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 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-03-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • The Euler function
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档