【欧拉函数】 poj 2478
递推法求欧拉函数:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
;
long long phi[maxn];
void make_phi()
{
;i<maxn;++i)
phi[i]=i;
;i<maxn;++i)
{
if(phi[i]==i)
{
for(long long j=i;j<maxn;j+=i)
{
phi[j]=phi[j]-phi[j]/i;
}
}
}
}
long long ans[maxn];
void make_ans()
{
ans[]=;
;i<maxn;++i)
ans[i]=ans[i-]+phi[i];
}
int main()
{
// freopen("in","r",stdin);
make_phi();
make_ans();
// for(long long i=2;i<=10;++i)
// cout << phi[i] <<endl;
long long n;
&& n)
{
printf("%lld\n",ans[n]);
}
;
}
素数打表法求欧拉函数:
这里有个小插曲就是note【maxn+1】原来maxn没有加一RE了n次,经刘卓大神指教瞬间改正
之前还以为是cin和cout不能接收long long 呢
#include <cstdio>
#include <iostream>
#include <stdlib.h>
using namespace std;
;
];
int main()
{
//freopen("in.txt","r",stdin);
long long *phi,i,j;
long long *prime;
prime=()*sizeof(long long));
prime[]=prime[]=;
;i<=maxn;i++)
prime[i]=;
;i*i<=maxn;i++)
{
if(prime[i])
{
for(j=i*i;j<=maxn;j+=i)
prime[j]=;
}
}
phi=()*sizeof(long long));
;i<=maxn;i++)
phi[i]=i;
;i<=maxn;i++)
{
if(prime[i])
{
for(j=i;j<=maxn;j+=i)
phi[j]=phi[j]/i*(i-);
}
}
note[]=;
;i<=maxn;i++)
{
note[i]=note[i-]+phi[i];
}
long long n;
while(cin >> n && n)
{
cout << note[n] << endl;
}
// while(scanf("%lld",&n)==1 && n)
// {
// printf("%lld\n",note[n]);
//}
;
}
【欧拉函数】 poj 2478的更多相关文章
- 欧拉函数 &【POJ 2478】欧拉筛法
通式: $\phi(x)=x(1-\frac{1}{p_1})(1-\frac{1}{p_2})(1-\frac{1}{p_3}) \cdots (1-\frac{1}{p_n})$ 若n是质数p的k ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- 欧拉函数 & 【POJ】2478 Farey Sequence & 【HDU】2824 The Euler function
http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...
- POJ 2478 欧拉函数打表的运用
http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...
- POJ 2478 线性递推欧拉函数
题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...
- 数学之欧拉函数 &几道poj欧拉题
欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...
随机推荐
- ubuntu显卡驱动安装及设置
转自: Ubuntu 14.04 Nvidia显卡驱动安装及设置 更换主板修复grub 引导后,无法从Nvidia进入系统(光标闪烁), 可能是显卡驱动出了问题. 1. 进入BIOS设置, 从集成 ...
- lorem ipsum text占位符
Web开发者通常用lorem ipsum text来做占位符,占位符就是占着位置的一些文字,没有实际意义. 为什么叫lorem ipsum text呢? 是因为lorem ipsum是古罗马西塞罗谚语 ...
- 设计模式 单例模式(Singleton) [ 转载2 ]
设计模式 单例模式(Singleton) [ 转载2 ] @author java_my_life 单例模式的结构 单例模式的特点: 单例类只能有一个实例. 单例类必须自己创建自己的唯一实例. 单例类 ...
- hdu_4283_You Are the One(区间DP)
题目链接:hdu_4283_You Are the One 题意: 有n个人,每个人有个屌丝值,如果果他是第K个上场,不开心指数就为(K-1)*D,然后有个小黑屋,可以调整他们的出场顺序,现在让你调整 ...
- C++构造与析构
C++语言构造函数与析构函数需要注意的地方. 构造 考虑以下定义 struct Node { char *name; int value; Node() { name = ]; strcpy(name ...
- 使用JavaScript进行数组去重——一种高效的算法
最近比较忙,没时间更新博客,等忙完这阵子会整理一篇使用AngularJS构建一个中型的单页面应用(SPA)的文章,尽情期待!先占个坑. 数组去重的算法有很多种,以下是一种. 思路如下: 定义一个空的对 ...
- C#获取数字证书
string Thumbprint = "C2489D912F247C187AA14B1291A6fB612281225D"; X509Store store = new X509 ...
- 关于NLog的target和Layout
这个没啥好说的,都是用别人的东西,看文档就行了,写的很详细. https://github.com/NLog/NLog/wiki/Configuration-file https://github.c ...
- 朋友遇到过的t厂面试题
朋友遇到过的t面试题 leetcode160 找链表交点 leetcode206 反转链表
- mac 隐藏 显示 文件
显示:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏:defaults write com.apple.finder Ap ...