HDOJ 2824 The Euler function(欧拉函数+打表法)
来源:互联网 发布:淘宝商城童装毛衣女孩 编辑:程序博客网 时间:2024/05/22 12:14
The Euler function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4516 Accepted Submission(s): 1878
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
题意:给出a,b两个数。(n)表示小于或者等于n的正整数中与n互质的个数。求(a)+(a+1)+.....+(b)的值。
很明显是欧拉函数问题,a,b值的上限很大,所以必须打表。不懂打表代码,只有死记模板了。
欧拉函数打表,代码如下:
<span style="font-size:12px;">#include<cstdio>#include<cstring>#define maxn 3000010__int64 res[maxn];__int64 euler(){int i,j;memset(res,0,sizeof(res));res[1]=1;for(i=2;i<maxn;++i)//先打表出每个数的互质数个数 {if(!res[i]){for(j=i;j<maxn;j+=i){if(!res[j])res[j]=j;res[j]=res[j]/i*(i-1);}}}for(i=2;i<maxn;++i)//再循环相加,找出从1到这个数的互质数和 res[i]+=res[i-1];}int main(){euler();int a,b;while(scanf("%d%d",&a,&b)!=EOF) printf("%I64d\n",res[b]-res[a-1]);return 0;}</span>
0 0
- HDOJ 2824 The Euler function(欧拉函数+打表法)
- 【欧拉函数】 HDOJ 2824 The Euler function
- HDOJ 题目2824 The Euler function(欧拉函数)
- hdoj 2824 The Euler function(欧拉函数打表)
- hdoj 2824 The Euler function 【欧拉函数 简单】
- HDOJ The Euler function 2824【欧拉函数】
- hdoj 2824 The Euler function 【欧拉函数】
- The Euler function(hdoj --2824-欧拉函数)
- HDOJ 2824 The Euler function (欧拉函数)
- HDOJ-----2824The Euler function欧拉函数
- HDOJ 2824 The Euler function (欧拉函数)
- 2824 The Euler function【欧拉函数】
- HDOJ 2824 The Euler function (欧拉函数打表)
- hdoj The Euler function 2824 (欧拉函数打表)
- The Euler function(欧拉函数)
- hdu2824 The Euler function (欧拉函数)
- hdu2824 The Euler function 欧拉函数
- hdu2824 The Euler function 欧拉函数
- Linux系统程序员的错误处理
- 排序算法(七)希尔排序
- SDKD Summer Team Contest S
- UML——类图
- Libgdx 之 饱和度与色相的渲染
- HDOJ 2824 The Euler function(欧拉函数+打表法)
- Linux系统C程序员的环境变量和环境表
- HDU 5399(Too Simple-判定映射)
- 每天进步一点点——Linux中的文件描述符与打开文件之间的关系
- OL记载Arcgis Server切片
- Linux系统C语言操作环境变量的函数
- Round A APAC Test 2016 Problem A. Googol String
- HOJ 13415 Website Tour(强连通缩点+多重背包dp)
- Nginx从入门到精通