hdu 2824 The Euler function
来源:互联网 发布:python爬取天气数据 编辑:程序博客网 时间:2024/05/16 14:31
题目描述:求区间[a,b]内所有整数的欧拉函数的和,有多组数据
【分析】
裸的欧拉函数,参见百度百科 [传送门]
【代码】
//hdu 2824 The Euler function#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#define fo(i,j,k) for(int i=j;i<=k;i++)using namespace std;const int N=3000001;int m[N],p[N],phi[N];long long ans=0;inline void getphi(){ fo(i,2,N) { if(!m[i]) p[++p[0]]=m[i]=i,phi[i]=i-1; for(int j=1;j<=p[0] && i*p[j]<N;j++) { m[i*p[j]]=p[j]; if(i%p[j]==0) { phi[i*p[j]]=phi[i]*p[j]; break; } else phi[i*p[j]]=phi[i]*(p[j]-1); } }}int main(){ int a,b; while(scanf("%d%d",&a,&b)==2) { ans=0; getphi(); fo(i,a,b) ans+=phi[i]; cout<<ans<<endl; } return 0;}
1 0
- HDU 2824:The Euler function【Euler】
- HDU 2824 The Euler function
- hdu 2824 The Euler function
- Hdu 2824 The Euler function
- [HDU 2824]The Euler function
- hdu 2824 The Euler function
- hdu 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- hdu 2824 The Euler function
- HDU 2824 The Euler function
- hdu 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824The Euler function
- hdu 2824 The Euler function
- 05-CoreData Scalar
- 进程与线程的一个简单解释
- Android 6.0 Overview Screen实现原理
- 邦德 纪中 1236 状压dp
- UIDynamic 入门基础
- hdu 2824 The Euler function
- 尾盘次新股杀跌
- BinderService简单应用
- Cannot retrieve metalink for repository: epel. Please verify its path and try again
- iOS8自定义Collection View Cell - Swift教程
- 连续签到奖励 数据库如何设计?
- 设计模式:单例模式
- Oracle数据库-建库、建表空间,建用户
- Mac下关于百度开发者中心认领应用