hduoj-2824【欧拉函数】
来源:互联网 发布:unity3d小球滚动 编辑:程序博客网 时间:2024/06/05 17:42
题目链接:点击打开链接
The Euler function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6405 Accepted Submission(s): 2691
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
思路:欧拉函数裸题,注意优化内存,开一个数组就行。
#include<cstdio>#include<algorithm>#include<cstring>#define LL long longusing namespace std;const int MAXN=3e6;int a,b;LL eu[MAXN+10]={0};void euler(){eu[1]=1;for(int i=2;i<=MAXN;i++){if(!eu[i]){for(int j=i;j<=MAXN;j+=i){if(!eu[j])eu[j]=j;eu[j]=eu[j]/i*(i-1);}}}for(int i=1;i<=MAXN;i++)eu[i]=eu[i-1]+eu[i];}int main(){euler();while(~scanf("%d%d",&a,&b)){printf("%lld\n",eu[b]-eu[a-1]);}return 0;}
0 0
- hduoj-2824【欧拉函数】
- hduoj 2824 The Euler function【欧拉函数 打表】
- hduoj 1116 并查集+欧拉回路
- hdu 2824 欧拉函数
- 欧拉函数 hdu 2824
- hdu 2824(欧拉函数)
- Hdu 2824 欧拉函数的应用
- 2824 The Euler function【欧拉函数】
- 【杭电2824】欧拉函数
- 欧拉函数
- 欧拉函数
- Relatives 【欧拉函数】
- 欧拉函数
- POJ_2407_欧拉函数
- 欧拉函数
- hdu_3501_欧拉函数
- 欧拉函数
- 欧拉函数
- jsp标准标签库
- Java基础学习(五)
- 容斥原理 && 欧拉函数 && 抽屉原理
- [codeforces117E]Tree or not Tree
- 搭建一个spring-boot项目 4
- hduoj-2824【欧拉函数】
- List.addAll()操作总结
- CodeForces
- [jzoj4665][CF407E]k-d-sequence
- 个人对this总结
- bzoj1634
- 云计算与数据中心
- Java Groovy集成
- 服务端主动终止连接的情况分析