递推法求欧拉函数:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. using namespace std;
  5. ;
  6. long long phi[maxn];
  7. void make_phi()
  8. {
  9. ;i<maxn;++i)
  10. phi[i]=i;
  11. ;i<maxn;++i)
  12. {
  13. if(phi[i]==i)
  14. {
  15. for(long long j=i;j<maxn;j+=i)
  16. {
  17. phi[j]=phi[j]-phi[j]/i;
  18. }
  19. }
  20. }
  21. }
  22. long long ans[maxn];
  23. void make_ans()
  24. {
  25. ans[]=;
  26. ;i<maxn;++i)
  27. ans[i]=ans[i-]+phi[i];
  28. }
  29. int main()
  30. {
  31. // freopen("in","r",stdin);
  32. make_phi();
  33. make_ans();
  34. // for(long long i=2;i<=10;++i)
  35. // cout << phi[i] <<endl;
  36. long long n;
  37. && n)
  38. {
  39. printf("%lld\n",ans[n]);
  40. }
  41. ;
  42. }

素数打表法求欧拉函数:

这里有个小插曲就是note【maxn+1】原来maxn没有加一RE了n次,经刘卓大神指教瞬间改正

之前还以为是cin和cout不能接收long long 呢

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. using namespace std;
  5. ;
  6. ];
  7. int main()
  8. {
  9. //freopen("in.txt","r",stdin);
  10. long long *phi,i,j;
  11. long long *prime;
  12. prime=()*sizeof(long long));
  13. prime[]=prime[]=;
  14. ;i<=maxn;i++)
  15. prime[i]=;
  16. ;i*i<=maxn;i++)
  17. {
  18. if(prime[i])
  19. {
  20. for(j=i*i;j<=maxn;j+=i)
  21. prime[j]=;
  22. }
  23. }
  24. phi=()*sizeof(long long));
  25. ;i<=maxn;i++)
  26. phi[i]=i;
  27. ;i<=maxn;i++)
  28. {
  29. if(prime[i])
  30. {
  31. for(j=i;j<=maxn;j+=i)
  32. phi[j]=phi[j]/i*(i-);
  33. }
  34. }
  35. note[]=;
  36. ;i<=maxn;i++)
  37. {
  38. note[i]=note[i-]+phi[i];
  39. }
  40. long long n;
  41. while(cin >> n && n)
  42. {
  43. cout << note[n] << endl;
  44. }
  45.  
  46. // while(scanf("%lld",&n)==1 && n)
  47. // {
  48. // printf("%lld\n",note[n]);
  49. //}
  50. ;
  51. }

【欧拉函数】 poj 2478的更多相关文章

  1. 欧拉函数 &【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 ...

  2. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)

    http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...

  4. 欧拉函数 & 【POJ】2478 Farey Sequence & 【HDU】2824 The Euler function

    http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...

  5. POJ 2478 欧拉函数打表的运用

    http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...

  6. poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

    http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...

  7. hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数

    hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...

  8. POJ 2478 线性递推欧拉函数

    题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...

  9. 数学之欧拉函数 &几道poj欧拉题

    欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...

随机推荐

  1. input编辑框编辑状态切换

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. Ajax中参数带有html格式的 传入后台保存【一】

    因业务需求  要讲如下编辑器中带有样式的数据传入数据库保存 第一种方法  json格式传入 $(".privilegezn_page .btn_ok").click(functio ...

  3. Java 向SQL Server插入文件数据

    package sqlserver; import java.util.Date; import java.util.UUID; import java.text.SimpleDateFormat; ...

  4. Java 泛型 通配符类型

    Java 泛型 通配符类型 @author ixenos 摘要:限定通配符类型.无限定通配符类型.与普通泛型区别.通配符捕获 通配符类型 通配符的子类型限定(?都是儿孙) <? extends ...

  5. Infix to postfix without '(' and ')'

    #include<iostream> #include<stack> #include<string> #include<deque> using na ...

  6. jQuery实例2

    下拉框实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  7. wuzhi 五指 数据库仿 thinkphp

    在/coreframe/app/模块/libs/class/mydb.class.php 中编辑 调用 : $mydb = load_class("mydb","模块&q ...

  8. chapter 13_4 跟踪table的访问

    __index和__newindex都是在table中没有所需访问的index时才发挥作用. 因此,只有将一个table保持为空,才有可能捕捉到所有对它的访问.为了监视一个table的所有访问,就应该 ...

  9. c/c++ 浮点型处理

    #include <stdio.h> #include <iostream> #include <string> #include <string.h> ...

  10. drupal7 开发block

    在自己开发的模块的module文件中,实现两个钩子:hook_block_info()和hook_block_view() function journal_block_info() { $block ...