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
 
Recommend
 
欧拉函数....
代码:
 #include<stdio.h>
#include<string.h>
const int maxn=;
__int64 phi[maxn];
int main()
{
int st,en,i,j;
for(i=;i<maxn;i++)
phi[i]=i;
for(i=;i<maxn;i+=)
phi[i]/=;
for(i=;i<maxn;i+=)
{
if(phi[i]==i)
{
for(j=i;j<maxn;j+=i)
{
phi[j]=phi[j]/i*(i-); /*from left to right*/
}
}
}
while(scanf("%d%d",&st,&en)!=EOF)
{ __int64 ans=;
for(i=st;i<=en;i++)
{
ans+=phi[i];
}
printf("%I64d\n",ans);
} return ;
}

HDUOJ-----2824The Euler function的更多相关文章

  1. hdu 2824The Euler function

    题目链接 快速求出a到b之间所有数的欧拉函数. 一个一个求肯定是不行的, 我们知道欧拉函数的公式为phi(n) = n*(1-1/i1)*(1-1/i2).......i1, i2为素因子. 那么我们 ...

  2. The Euler function[HDU2824]

    The Euler functionTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 2824 The Euler function

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. The Euler function(欧拉函数)

    The Euler function Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  5. hdu 2824 The Euler function(欧拉函数)

    题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...

  6. The Euler function(线性筛欧拉函数)

    /* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体 ...

  7. hdu 2824 The Euler function 欧拉函数打表

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. HDU 2824 The Euler function --------欧拉模板

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. hdu2824 The Euler function(欧拉函数个数)

    版权声明:本文为博主原创文章,未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/36426357 题目链接:h ...

随机推荐

  1. android 利用 aapt 解析 apk 得到应用名称 包名 版本号 权限等信息

    在上传各大市场时发现 apk 上传后能自动解析出应用名称.包名.版本号.使用权限等信息,所以就研究了一下 1 直接解压 apk 解析  AndroidManifest.xml 是不行的,因为 apk ...

  2. 第二章 ActionScript 3.0学习之画星星(鼠标及键盘事件)

    今天觉得学到的比较有趣,所以记录之......~~~ 下面这段就是画出星星的代码:StarShape.as package { import flash.display.Shape; import f ...

  3. @Java中使用Jedis操作Redis之一

    依赖的jar包:jedis <dependency> <groupId>redis.clients</groupId> <artifactId>jedi ...

  4. 混沌数学之Standard模型

    相关软件混沌数学之离散点集图形DEMO 相关代码: class StandardEquation : public DiscreteEquation { public: StandardEquatio ...

  5. Eclipse上传代码到GitHub

    平时工作学习中难免会在Github搜索一下开源的Android代码, Android系统本身的代码就是托管在GitHub上,如果平时随手做了一个Demo,托管在云盘感觉不入流,如果平时自己一时兴起写了 ...

  6. 8个对程序员来说有用的jQuery小贴士和技巧

    1) 禁用鼠标右键单击 jQuery程序员可以使用此代码在网页上禁用鼠标右键点击. 1 2 3 4 5 6 7 8 9 10 $(document).ready(function() {     // ...

  7. GO语言基础map与函数

    1. map 1. 类似其它语言中的哈希表活着字典,以 key-value 形式存储数据 2. key 必须是支持 == 或 != 比较运算的类型,不可以是函数.map 或 slice 3. map ...

  8. ListView 设置列对齐方式

    <ListView.Resources> <Style TargetType="ListViewItem"> <Setter Property=&qu ...

  9. TCP/IP协议族——IP工作原理及实例具体解释(上)

     IP协议具体解释 本文主要介绍了IP服务特点,头部结构,IP分片知识,并用tcpdump抓取数据包.来观察IP数据报传送过程中IP的格式,以及分片的过程. IP头部信息:IP头部信息出如今每一个 ...

  10. iOS判断日期A是否在日期B到日期C之间

    方法一: 可以用nsdate 的 timeIntervalSince1970 方法把时间转换成时间戳进行比较,这里timeIntervalSince1970返回的是NSTimeInterval(dou ...