/*
题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体证明看po主的博客 ^0^ #超时:这里直接用欧拉函数暴力搞还是不可以的,用到线性筛欧拉函数,这里总和爆int,要用long long */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
/**************************欧拉函数模板*****************************/
//筛选法打欧拉函数表
#define Max 3000010
int euler[Max];
void Init(){
euler[]=;
for(int i=;i<Max;i++)
euler[i]=i;
for(int i=;i<Max;i++)
if(euler[i]==i)
for(int j=i;j<Max;j+=i)
euler[j]=euler[j]/i*(i-);//先进行除法是为了防止中间数据的溢出
}
/**************************欧拉函数模板*****************************/
int a,b;
int main(){
// freopen("in.txt","r",stdin);
Init();
while(scanf("%d%d",&a,&b)!=EOF){
ll cur=;
for(int i=a;i<=b;i++){
cur+=euler[i];
}
printf("%lld\n",cur);
}
return ;
}

The Euler function

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 224 Accepted Submission(s): 124
 
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
2009 Multi-University Training Contest 1 - Host by TJU
 
Recommend
gaojie
 

The Euler function(线性筛欧拉函数)的更多相关文章

  1. 素数的线性筛 && 欧拉函数

    O(n) 筛选素数 #include<bits/stdc++.h> using namespace std; const int M = 1e6 + 10 ; int mindiv[M] ...

  2. 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和

    只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...

  3. [bzoj 2190][SDOI2008]仪仗队(线性筛欧拉函数)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 分析:就是要线性筛出欧拉函数... 直接贴代码了: memset(ans,,sizeof ...

  4. BZOJ 2190 仪仗队(线性筛欧拉函数)

    简化题意可知,实际上题目求得是gcd(i,j)=1(i,j<=n)的数对数目. 线性筛出n大小的欧拉表,求和*2+1即可.需要特判1. # include <cstdio> # in ...

  5. Bzoj 2186: [Sdoi2008]沙拉公主的困惑 乘法逆元,线性筛,欧拉函数,数论

    2186: [Sdoi2008]沙拉公主的困惑 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2560  Solved: 857[Submit][St ...

  6. poj1248 (线性筛欧拉函数)(原根)

    强烈鸣谢wddwjlss 题目大意:给出一个奇素数,求出他的原根的个数,多组数据. 这里先介绍一些基本性质 阶 设\((a,m)=1\),满足\(a^r \equiv 1 \pmod m\)的最小正整 ...

  7. The Euler function(hdoj --2824-欧拉函数)

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

  8. noip复习——线性筛(欧拉筛)

    整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...

  9. HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

    GTW likes function      Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...

随机推荐

  1. 关于XCode9的一些问题

    最近几天一直在做一项工作,为新项目在做搭建框架的前期准备,然后恰逢更新iOS11和XCode9,笔者心急的尝了个先,发现了一些问题,记录一下,如果有相同问题的程序猿,也可以参考一下. 目前问题遇到两点 ...

  2. JSP入门 el表达式

    我们已经知道el是jsp-2.0规范的一部分,tomcat-5.x版本以上都已经能够支持jsp-2.0规范,但在更低版本的tomcat和webphere,weblogic中还是无法使用这一便捷方式. ...

  3. hdu3695 ac自动机入门

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  4. 在Pycharm中使用jupyter笔记本

    在Pycharm中使用jupyter笔记本 我在Pycharm中使用jupyter笔记本,发现新的Jupyter更新中,增加了令牌. 随着创建的虚拟环境启动的所有设置,并将URL设置为127.0.0. ...

  5. 基于SSM之Mybatis接口实现增删改查(CRUD)功能

    国庆已过,要安心的学习了. SSM框架以前做过基本的了解,相比于ssh它更为优秀. 现基于JAVA应用程序用Mybatis接口简单的实现CRUD功能: 基本结构: (PS:其实这个就是用的Mapper ...

  6. Android签名机制---签名过程

    大神文章:http://blog.csdn.net/jiangwei0910410003/article/details/50402000 一.知识点 1.数据摘要(数据指纹).签名文件,证书文件 2 ...

  7. zoj1151 zoj1295 Word Reversal 字符串的简单处理

    Word Reversal Time Limit: 2 Seconds      Memory Limit:65536 KB For each list of words, output a line ...

  8. Shell一个文件并等待完成

    Option Explicit Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAcce ...

  9. UWP appButtonBar样式

    UWP 的appButtonBar使用<AppBarButton Icon = "Next" Label = "Next" /> Icon是 Sym ...

  10. Hibernate逆向代码问题

    问题描述 使用hibernate tools 插件生成pojo代码非常方便快捷,但是我今天使用的时候发现,在eclips安装jboss插件后,找不到Hibernate Code Generation ...