The Euler function

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

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
 
第一种打表的方法是,素数和欧拉,分开来打表。250ms
第二种打表只有一个,但是时间上更多。500ms
 
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; int prime[],len;
int opl[];
bool s[]; void Getprime() //打素数表
{
int i,j;
len=;
for(i=;i<=;i++)
{
if(s[i]==false)
{
prime[++len]=i;
for(j=i*;j<=;j=j+i)
s[j]=true;
}
}
} void Euler() //欧拉打表。
{
int i,j;
Getprime();
for(i=;i<=;i++)
opl[i]=i;
opl[]=;
for(i=;i<=len;i++)
{
for(j=prime[i];j<=;j=j+prime[i])
opl[j]=opl[j]/prime[i]*(prime[i]-); //利用的定理 }
} int main()
{
int n,m,i;
__int64 num;
Euler();
while(scanf("%d%d",&n,&m)>)
{
num=;
for(i=n;i<=m;i++)
num=num+opl[i];
printf("%I64d\n",num);
}
return ;
}

第二种方法。

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; int opl[];
bool s[]; void Euler() //欧拉打表。
{
int i,j;
for(i=;i<=;i++)
opl[i]=i;
opl[]=; for(i=;i<=;i++)
if(s[i]==false)
{
for(j=i;j<=;j=j+i)
{
opl[j]=opl[j]/i*(i-);
s[j]=true;
}
}
} int main()
{
int n,m,i;
__int64 num;
Euler();
while(scanf("%d%d",&n,&m)>)
{
num=;
for(i=n;i<=m;i++)
num=num+opl[i];
printf("%I64d\n",num);
}
return ;
}
 

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 欧拉函数筛 模板

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

  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

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

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

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

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

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

  8. HDU——T 2824 The Euler function

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

  9. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

随机推荐

  1. 盘点Xcode中开发者最喜爱的十大开源插件

    Xcode IDE拥有着诸如导航.重构.校准等众多非常高大上的工具,而予以辅助的插件更是在Xcode的基础上对相关功能进行改进与扩展.在应用开发过程中,通过开源包管理器Alcatraz对插件进行安装管 ...

  2. 一个钓鱼WiFi的破解

    在开始前我们先安装下工具 git clone [url]https://github.com/P0cL4bs/WiFi-Pumpkin.git[/url] [/size] [size=4][size= ...

  3. windows 安装nexus3

    下载地址 nexus官网下载页面 文件名:nexus-3.3.1-01-win64.zip,解压,cd到bin目录 运行: nexus.exe /run 1 安装成系统服务: nexus.exe /i ...

  4. elasticsearch中 refresh 和flush区别

    elasticsearch中有两个比较重要的操作:refresh 和 flush refresh操作 当我们向ES发送请求的时候,我们发现es貌似可以在我们发请求的同时进行搜索.而这个实时建索引并可以 ...

  5. [Python]Threading.Thread之Daemon线程

    之前对Daemon线程理解有偏差,特记录说明: 一.什么是Daemon A thread can be flagged as a "daemon thread". The sign ...

  6. Mcode的介绍

    开始时进行的Mcode代码积累平台的分析: 登录模块 Login.html登录页面进行用户的登录,把登录好的用户id存到session里面,转到代码模块 Register.html注册页面进行用户的注 ...

  7. 项目实体类使用@Data注解,但是项目业务类中使用getA(),setA()方法报错,eclipse中配置lombok

    @Data注解来源与Lombok,可以减少代码中大量的set get方法,大量减少冗余代码,但是今天部署项目时候,发现实体类使用@Data注解,但是项目业务类中使用getA(),setA()方法报错. ...

  8. node 本地静态服务器

    直接上代码 const connect = require("connect"); const serveStatic = require("serve-static&q ...

  9. 线性表 (单链表、循环链表-python实现)

    一.线性表 线性表的定义: 线性表是具有相同数据类型的有限数据的序列. 线性表的特点: 出了第一个元素外,每个元素有且仅有一个直接前驱,除最后一个元素外有且只有一个后继. 线性表是一种逻辑结构,表示元 ...

  10. Intellij-插件安装-安装CodeGenerator插件并且添加Builder模板

    Intellij IDEA 2018.1.2版本 CodeGenerator插件地址:https://github.com/lotabout/CodeGenerator/releases 步骤一:安装 ...