light oj 1007 Mathematically Hard (欧拉函数)
题目地址: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;
}
light oj 1007 Mathematically Hard (欧拉函数)的更多相关文章
- lightoj 1007 - Mathematically Hard 欧拉函数应用
题意:求[a,b]内所有与b互质个数的平方. 思路:简单的欧拉函数应用,由于T很大 先打表求前缀和 最后相减即可 初次接触欧拉函数 可以在素数筛选的写法上修改成欧拉函数.此外本题内存有限制 故直接计算 ...
- nyoj 1007 GCD(数学题 欧拉函数的应用)
GCD 描述 The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b) ...
- GCD nyoj 1007 (欧拉函数+欧几里得)
GCD nyoj 1007 (欧拉函数+欧几里得) GCD 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The greatest common divisor ...
- Reflect(欧拉函数)
Reflect Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- ACM学习历程—HYSBZ 2818 Gcd(欧拉函数 || 莫比乌斯反演)
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- COGS2531. [HZOI 2016]函数的美 打表+欧拉函数
题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k ...
随机推荐
- Beyond Compare 4提示已经过了30天试用期,破解方式,亲测可用
修改注册表 1)在搜索栏中输入 regedit ,打开注册表 2) 删除项目:计算机\HKEY_CURRENT_USER\Software\Scooter Software\Beyond Compar ...
- [苹果]苹果AppStore应用审核标准
[苹果]苹果AppStore应用审核标准 http://wenku.baidu.com/view/a9152d2c647d27284b7351a1.html 苹果app审核指南 http://we ...
- MCU PWM DAC OP Voltage Output
- LPC43xx Asymmetric Dual Core : Cortex-M0 and Cortex-M4
- LPC18xx and LPC43xx 选型及差异
Q LPC43xx和LPC18xx有相同的USB接口以及片内USB驱动吗?A 是的. Q LPC4300和LPC1800只是内核不同吗?外设和管脚配置都完全一致?A 为LPC18xx的映像可以直接在L ...
- LPC1800 and LPC4300 MCUs
LPC1800 Series microcontrollers At 180 MHz, LPC1800 Series microcontrollers combine the industry's f ...
- ARM Cortex Design Considerations for Debug
JTAG was the traditional mechanism for debug connections for ARM7/9 parts, but with the Cortex-M fam ...
- JTAG – A technical overview and Timing
This document provides you with interesting background information about the technology that underpi ...
- Uniscribe相关文章
相关资料很少 http://msdn.microsoft.com/en-us/library/windows/desktop/dd374127(v=vs.85).aspx http://www.cnb ...
- WCF消息传递
通过了解了WCF的一些基本概念并创建和编写WCF应用中的相应方法,实现了WCF服务和客户端之间的调用,就能够理解WCF应用是如何进行通信的.了解了一些基本的WCF概念后,还需要深入了解WCF消息的概念 ...