The Euler function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5028    Accepted Submission(s): 2123

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之间的每个数的欧拉函数的和

#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 3000010
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
LL s[MAX],a[MAX];
void el()
{
LL i,j;
for(i=2;i<MAX;i++)
{
if(!a[i])
{
for(j=i;j<MAX;j+=i)
{
if(!a[j]) a[j]=j;
a[j]=a[j]/i*(i-1);
}
}
a[i]+=a[i-1];
}
}
int main()
{
LL n,m,j,i,t;
el();
while(scanf("%lld%lld",&n,&m)!=EOF)
{
t=a[m]-a[n-1];
printf("%lld\n",t);
}
return 0;
}

  

hdu 2824 The Euler function的更多相关文章

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

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

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

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

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

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

  4. HDU——2824 The Euler function

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

  5. HDU - 2824 The Euler function 欧拉函数筛 模板

    HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include ...

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

    如果打表的话会超内存,我想到了一种方法解决这个问题.题目给出的数据时3000000,我将三百万分成300个数据,将整万的数据存储下来,计算的时候,先计算x和y之间整万的数据,然后再计算零散数据. 想法 ...

  7. HDU——T 2824 The Euler function

    http://acm.hdu.edu.cn/showproblem.php?pid=2824 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  8. 欧拉函数 & 【POJ】2478 Farey Sequence & 【HDU】2824 The Euler function

    http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...

  9. HDU 2824.The Euler function-筛选法求欧拉函数

    欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2…pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...

随机推荐

  1. 演练:Office 编程(C# 和 Visual Basic)

    https://msdn.microsoft.com/zh-cn/library/ee342218(v=vs.110).aspx PIA的全称是 primary interop assembly  主 ...

  2. MyBatis学习总结(5)——实现关联表查询

    一对一关联 提出需求 根据班级id查询班级信息(带老师的信息) 创建表和数据 创建一张教师表和班级表,假设一个老师负责教一个班,那么老师和班级之间的关系就是一对一的关系. create table t ...

  3. 【Todo】深入理解Javascript系列

    真的很好,要看 http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html

  4. 真正解决ASP.NET每一个页面首次访问超级慢的问题 (转载)

    原文:http://www.afuhao.com/article_articleId-219.shtml 摘要:ASP.NET页面首次打开很慢,但别的页面如果没有访问过,去访问也会慢.你也许认为它是在 ...

  5. CodeForces Round #290 Fox And Dinner

    而是Div2的最后一题,当时打比赛的时候还不会最大流.自己能够把它写出来然后1A还是很开心的. 题意: 有n个不小于2的整数,现在要把他们分成若干个圈.在每个圈中,数字的个数不少于3个,而且相邻的两个 ...

  6. facebook海量图片存储系统与淘宝TFS系统比较

    本篇论文的原文可谓通俗易懂.行云流水.结构清晰.图文并茂……正如作者所说的——"替换Facebook的图片存储系统就像高速公路上给汽车换轮子,我们无法去追求完美的设计……我们花费了很多的注意 ...

  7. I.MX6 隐藏电池图标

    /********************************************************************** * I.MX6 隐藏电池图标 * 声明: * 有些时候设 ...

  8. git - svn 平滑到 git

    1. 建立自己的git仓库,需要是空git仓库 2. checkout 你的 git仓库 3. svn忽略.git文件,忽略.git  .gitignore 4. 把 .git文件拷到你的 svn仓库 ...

  9. SpringMVC——hello SpringMVC

    概述: Spring的web框架围绕DispatcherServlet设计. DispatcherServlet的作用是将请求分发到不同的处理器. 与其它web MVC框架一样,Spring的web ...

  10. ASIHttpRequest编译不通过

    转:http://blog.sina.com.cn/s/blog_67a5e47201014tof.html Undefined symbols for architecture i386:   &q ...