light oj 1007 Mathematically Hard (欧拉函数)
来源:互联网 发布:pony运动鞋 知乎 编辑:程序博客网 时间:2024/05/15 12:11
题目地址:light oj 1007
第一发欧拉函数。
欧拉函数重要性质:
设a为N的质因数,若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N / a) * a;若(N % a == 0 && (N / a) % a != 0) 则有:E(N) = E(N / a) * (a - 1)
对于这题来说,首先卡MLE。。只能开一个数组。。所以把前缀和也存到欧拉数组里。然后卡long long。。要用unsigned long long 。。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>#include <time.h>using namespace std;#define LL long long#define pi acos(-1.0)#pragma comment(linker, "/STACK:1024000000")const int mod=9901;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=5000000+10;unsigned LL euler[MAXN];void init(){ int i, j, max1=5000000; for(i=2;i<=max1;i++){ euler[i]=i; } for(i=2;i<=max1;i++){ if(euler[i]!=i) continue ; for(j=i;j<=max1;j+=i){ euler[j]=euler[j]/i*(i-1); } } for(i=2;i<=max1;i++){ euler[i]=euler[i-1]+euler[i]*euler[i]; }}int main(){ int t, l, r, icase=0; scanf("%d",&t); init(); while(t--){ scanf("%d%d",&l,&r); printf("Case %d: %llu\n",++icase,euler[r]-euler[l-1]); } return 0;}
1 0
- light oj 1007 Mathematically Hard (欧拉函数)
- light oj 1007 Mathematically Hard (欧拉函数)
- Light OJ 1007 Mathematically Hard [欧拉函数+前缀和]【数论】
- Light OJ 1007 - Mathematically Hard
- Light oj 1007 - Mathematically Hard
- lightoj 1007 - Mathematically Hard 欧拉函数
- lightoj 1007 - Mathematically Hard 欧拉函数
- LightOJ 1007 Mathematically Hard 欧拉函数
- LightOJ-1007-Mathematically Hard [欧拉函数]
- LIGHTOJ 1007 – MATHEMATICALLY HARD【欧拉函数】
- lightoj 1007Mathematically Hard (欧拉函数水题)
- LightOJ1007---Mathematically Hard (欧拉函数)
- LightOJ1007 Mathematically Hard 欧拉函数+前缀和
- Mathematically Hard (欧拉定理)
- LightOJ 1007 Mathematically Hard
- LightOJ 1007 Mathematically Hard
- Light OJ 1375 LCM Extreme 欧拉函数 (或 莫比乌斯反演 ?)
- Light OJ 1307 Bi-shoe and Phi-shoe(欧拉函数)
- HDOJ1233 还是畅通工程(kru)
- KVM内核如何实现底层虚拟机创建功能
- 安装StartBBS 遇到的问题
- set yum source to cdrom
- mysql使用命令小结
- light oj 1007 Mathematically Hard (欧拉函数)
- 计蒜客 难题题库 139 字符全排列
- PLS-00103:Encountered the symbol "EXIT" when expecting one of the following:.( ,%
- cout,printf等无控制台输出
- 指针数组,数组指针,函数指针,main函数实质,二重指针,函数指针作为参数,泛型函数
- caffe安装指南
- 之字形打印二叉树
- 用ajax传递json对象数组的方法
- FineReport集成到AWS系统中的方案