hdu 2824 The Euler function
来源:互联网 发布:电气原理图制图软件 编辑:程序博客网 时间:2024/06/04 20:07
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824
题意:求出a-b之间的欧拉函数的总和
代码:
#include<stdio.h>#include<iostream>#include <memory.h>#include<algorithm>#include <math.h>using namespace std;#define ll long longconst int maxn = 3000010;int minDIv[maxn], phi[maxn], sum[maxn];//多个数求欧拉函数 时间复杂度 O(nlogn)void genPhi(){ for(int i = 1; i < maxn; i++) { minDIv[i] = i; } for(int i = 2; i * i < maxn ; i ++) { if(minDIv[i] == i) { for(int j = i * i; j < maxn ; j += i) { minDIv[j] = i; } } } phi[1]= 1; for(int i = 2; i < maxn ; i ++) { phi[i] = phi[i / minDIv[i]]; if( (i / minDIv[i]) % minDIv[i]==0 ) { phi[i] *= minDIv[i]; }else { phi[i] *= minDIv[i] - 1; } }}int main(){ int m,n; ll ans = 0; genPhi(); while(cin>>m>>n) { for(int i = m; i <= n ; i ++) { ans += phi[i]; } cout<<ans<<endl; ans = 0; } return 0;}
注意事项:要进行打表操作,不然会超时.
0 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
- 微信验证token失败的解决
- H5是一个全新的课题吗?
- CyU3PSpiInit 错误(返回0x44)
- 学习的起点2016.11.14
- LINUX进程相关的几个函数
- hdu 2824 The Euler function
- hdu4405_Aeroplane chess
- Eclipse如何输入一个或几个字母后,自动联想后边的字母
- 利用RxJava获取手机已安装的App的图片、应用名称和版本号
- HDU4283——You Are the One (区间DP)
- Python异常处理 -跳过异常继续执行
- MYSQL的COMMIT和ROLLBACK
- html5的一些新特性
- Python-【基础】-Windows平台搭建一个完整的IDE环境