题目链接

快速求出a到b之间所有数的欧拉函数。

一个一个求肯定是不行的, 我们知道欧拉函数的公式为phi(n) = n*(1-1/i1)*(1-1/i2).......i1, i2为素因子。 那么我们就可以先将每一个数的欧拉函数值预处理出来。

具体看代码

 #include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 3e6+;;
int f[maxn];
int main()
{
int t, n, m, cnt;
for(int i = ; i<=maxn; i++) {
f[i] = i;
}
for(int i = ; i<maxn; i++) {
if(f[i] == i) { //如果f[i] == i, 说明这个数是素数
for(int j = i; j<maxn; j+=i) {
f[j] = f[j]/i*(i-); //f[j]*(1-1/i)
}
}
}
while(~scanf("%d%d", &n, &m)) {
ll sum = ;
for(int i = n; i<=m; i++) {
sum += f[i];
}
cout<<sum<<endl;
}
}

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

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

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

  2. HDU——T 2824 The Euler function

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

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

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

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

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

  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 step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

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

  9. Day7 - D - The Euler function HDU - 2824

    The Euler function phi is an important kind of function in number theory, (n) represents the amount ...

随机推荐

  1. postgreSQL远程连接出现:Error connecting to server :致命错误 SSL关闭的pg_hba.conf记录

    异常截图:

  2. 为什么getline()后要两次回车????(将输入的字符串按单词倒序输出)

    #include<iostream>#include<string>#include<algorithm>using namespace std;int main( ...

  3. JVM学习之类的卸载机制

    类的生命周期 当Sample类被加载.连接和初始化后,它的生命周期就开始了,当代表Sample类的Class对象不再被引用,即不可触及时,Class对象就会结束生命周期,Sample类在方法区内的数据 ...

  4. Android GridView(九宫图)

    GridView跟ListView都是比较常用的多控件布局,而GridView更是实现九宫图的首选! <?xml version="1.0" encoding="u ...

  5. Microsoft.AlphaImageLoader滤镜讲--透明处理<转>

    Microsoft.AlphaImageLoader是IE滤镜的一种,其主要作用就是对图片进行透明处理.虽然FireFox和IE7以上的IE浏览器已经支持透明的PNG图片,但是就IE5-IE6而言还是 ...

  6. WebRTC 音视频开发

    WebRTC 音视频开发 webrtc   Android IOS WebRTC 音视频开发总结(七八)-- 为什么WebRTC端到端监控很关键? 摘要: 本文主要介绍WebRTC端到端监控(我们翻译 ...

  7. Ant Table组件

    http://www.cnblogs.com/hujunzheng/p/5689650.html React中使用Ant Table组件   v一.Ant Design of React http:/ ...

  8. 提醒录入BOM更改原因

    应用 Oracle Bill Of   Materiel 层 Level Function 函数名 Funcgtion Name BOM_BOMFDBOM 表单名 Form Name BOMFDBOM ...

  9. WISPr1.0

    王桢珍 王兵 侯志强 苑红 中国移动研究院 网络技术研究所, 北京100053 摘要   本文详细介绍了WLAN国际漫游的WISPr1.0技术规范并探讨其具体实现,包括基于WISPr1.0的WLAN国 ...

  10. 第三届蓝桥杯预赛真题_第一题_两种微生物 X 和 Y

    /* 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y. 现在已 ...