HDU - 2824 The Euler function 欧拉函数筛 模板
题意:
求【a,b】间的欧拉函数和。这道题卡内存,只能开一个数组。
思路:
ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) 。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cctype>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
const int maxn = ; ll sum[maxn];
/*
const int maxn = 3000009;
int prime[316819];
int phi[maxn];
ll sum[maxn];
bool flag[maxn];
void getphi(){
phi[1] = 1,sum[1] = 1;
int tot = 0;
for(int i=2; i<maxn; i++){
if(flag[i] == 0){
prime[++tot] = i;
phi[i] = i-1;
}
for(int j=1; i * prime[j] < maxn && j<=tot; j++){
flag[i*prime[j]] = 1;
if(i%prime[j] == 0){
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i]*(prime[j] - 1);
}
sum[i] = sum[i-1] + phi[i];
} }
*/
void getphi(){
sum[] = ;
for(int i=; i<maxn; i++){
if(!sum[i]){
for(int j=i; j<maxn; j+=i){
if(!sum[j])sum[j] = j;
sum[j] = sum[j] / i * (i-);
}
}
}
for(int i=; i<maxn; i++)sum[i] += sum[i-];
}
int main(){
int a,b;
getphi();
while(~scanf("%d%d", &a, &b)){
printf("%lld\n", sum[b] - sum[a-]);
} return ;
}
HDU - 2824
还有POJ的2478也是区间累计欧拉函数的和
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cctype>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
const int maxn = ; ll sum[maxn];
void getphi(){
sum[] = ;
for(int i=; i<maxn; i++){
if(!sum[i]){
for(int j=i; j<maxn; j+=i){
if(!sum[j])sum[j] = j;
sum[j] = sum[j] / i * (i-);
}
}
}
for(int i=; i<maxn; i++)sum[i] += sum[i-];
}
int main(){
int a;
getphi();
while(~scanf("%d", &a) && a){
printf("%lld\n", sum[a]);
} return ;
}
POJ2478
HDU - 2824 The Euler function 欧拉函数筛 模板的更多相关文章
- hdu 2824 The Euler function(欧拉函数)
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...
- hdu 2824 The Euler function 欧拉函数打表
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
- (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 ...
- HDU 2824 The Euler function --------欧拉模板
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 5597 GTW likes function 欧拉函数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...
- hdu 2824 The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU——2824 The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 4483 Lattice triangle(欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情 ...
随机推荐
- 树莓派 + Windows IoT Core 搭建环境监控系统
前言:Windows IoT 是微软为嵌入式开发板设计的一种物联网操作系统,运行Windows UWP(C# 开发),可以设计出丰富的交互界面,驱动GPIO,连接一些传感器做有意思的事,本文详细介绍如 ...
- 国内CDH的MAVEN代理
在编译CDH版本的各个开源软件时,需要从cdh-repo下载对应的jar包,但发现下载速度非常慢,甚至有时候出现下载异常的情况. 下面是国内可用的.速度非常快的一个maven代理仓库,亲测可用: ht ...
- Jenkins 配置 SpringBoot 自动构建部署
服务器版本 Linux version 3.10.0-957.12.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8 ...
- 不等"金九银十",金风八月,我早已拿下字节跳动的offer
字节跳动,我是在网上投的简历,之前也投过一次,简历都没通过删选,后来让师姐帮我改了一下简历,重新投另一个部门,获得了面试机会.7月23日,中午HR打电话过来预约了下午4点半面试,说会在线写代码,让我准 ...
- pytest
pytest可以生成多种样式的结果:1.生成JunitXML格式测试报告:命令: --junitxml=path(相对路径)2.生成result log 格式的测试报告: 命令:--resultlog ...
- 第十五章 LVM管理和ssm存储管理器使用 随堂笔记
第十五章 LVM管理和ssm存储管理器使用 本节所讲内容: 15.1 LVM的工作原理 15.2 创建LVM的基本步骤 15.3 实战-使用SSM工具为公司的邮件服务器创建可动态扩容的存储池 LVM的 ...
- Java小白进阶之值传递-引用传递
class ClassA{ int value;//成员变量 } public class TestClassA{ public static void main(String args[]){ in ...
- react学习(二)--元素渲染
元素用来描述你在屏幕上看到的内容: const element = <h1>Hello, world</h1>; 与浏览器的 DOM 元素不同,React 当中的元素事实上是普 ...
- c#自定义控件中的事件处理
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- Springboot 优雅停止服务的几种方法
在使用Springboot的时候,都要涉及到服务的停止和启动,当我们停止服务的时候,很多时候大家都是kill -9 直接把程序进程杀掉,这样程序不会执行优雅的关闭.而且一些没有执行完的程序就会直接退出 ...