【欧拉函数】 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> ...
随机推荐
- input编辑框编辑状态切换
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Ajax中参数带有html格式的 传入后台保存【一】
因业务需求 要讲如下编辑器中带有样式的数据传入数据库保存 第一种方法 json格式传入 $(".privilegezn_page .btn_ok").click(functio ...
- Java 向SQL Server插入文件数据
package sqlserver; import java.util.Date; import java.util.UUID; import java.text.SimpleDateFormat; ...
- Java 泛型 通配符类型
Java 泛型 通配符类型 @author ixenos 摘要:限定通配符类型.无限定通配符类型.与普通泛型区别.通配符捕获 通配符类型 通配符的子类型限定(?都是儿孙) <? extends ...
- Infix to postfix without '(' and ')'
#include<iostream> #include<stack> #include<string> #include<deque> using na ...
- jQuery实例2
下拉框实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- wuzhi 五指 数据库仿 thinkphp
在/coreframe/app/模块/libs/class/mydb.class.php 中编辑 调用 : $mydb = load_class("mydb","模块&q ...
- chapter 13_4 跟踪table的访问
__index和__newindex都是在table中没有所需访问的index时才发挥作用. 因此,只有将一个table保持为空,才有可能捕捉到所有对它的访问.为了监视一个table的所有访问,就应该 ...
- c/c++ 浮点型处理
#include <stdio.h> #include <iostream> #include <string> #include <string.h> ...
- drupal7 开发block
在自己开发的模块的module文件中,实现两个钩子:hook_block_info()和hook_block_view() function journal_block_info() { $block ...