求1~n的欧拉函数的值

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <queue>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <cstring>
  7. #define inf 2147483647
  8. #define N 1000010
  9. #define p(a) putchar(a)
  10. #define For(i,a,b) for(long long i=a;i<=b;++i)
  11.  
  12. using namespace std;
  13. long long n;
  14. long long a[N];
  15. void in(long long &x){
  16. long long y=;char c=getchar();x=;
  17. while(c<''||c>''){if(c=='-')y=-;c=getchar();}
  18. while(c<=''&&c>=''){ x=(x<<)+(x<<)+c-'';c=getchar();}
  19. x*=y;
  20. }
  21. void o(long long x){
  22. if(x<){p('-');x=-x;}
  23. if(x>)o(x/);
  24. p(x%+'');
  25. }
  26.  
  27. int main(){
  28. a[]=;
  29. For(i,,1e6)
  30. if(!a[i])
  31. for(long long j=i;j<=1e6;j+=i){
  32. if(!a[j]) a[j]=j;
  33. a[j]=a[j]/i*(i-);
  34. }
  35. For(i,,1e6)
  36. a[i]+=a[i-];
  37. while(cin>>n&&n){
  38. o(a[n]-);p('\n');
  39. }
  40. return ;
  41. }

筛法求欧拉函数(poj2478的更多相关文章

  1. AcWing 874. 筛法求欧拉函数

    #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int primes[N],cnt; int ph ...

  2. hdu 2814 快速求欧拉函数

    /** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...

  3. 欧拉函数,打表求欧拉函数poj3090

    欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i ...

  4. HDU2824-The Euler function-筛选法求欧拉函数+求和

    欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2-pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...

  5. HDU 2824.The Euler function-筛选法求欧拉函数

    欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2…pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...

  6. 【poj2478-Farey Sequence】递推求欧拉函数-欧拉函数的几个性质和推论

    http://poj.org/problem?id=2478 题意:给定一个数x,求<=x的数的欧拉函数值的和.(x<=10^6) 题解:数据范围比较大,像poj1248一样的做法是不可行 ...

  7. O(n)求素数,求欧拉函数,求莫比乌斯函数,求对mod的逆元,各种求

    筛素数 void shai() { no[1]=true;no[0]=true; for(int i=2;i<=r;i++) { if(!no[i]) p[++p[0]]=i; int j=1, ...

  8. uva 10820 (筛法构造欧拉函数)

    send a table When participating in programming contests, you sometimes face the following problem: Y ...

  9. 【learning】杜教筛求欧拉函数前缀和

    我们考虑利用\(\sum\limits_{d|n}\varphi(d)=n\)这一性质来处理这个问题 设\(f(n)=\sum\limits_{i=1}^{n}\varphi(i)\) 那么我们可以得 ...

随机推荐

  1. Python3 From Zero——{最初的意识:006~数据编码与处理}

    一.读写CSV数据: #!/usr/bin/env python3 #-*- coding=utf8 -*- import csv with open('kxtx.csv', 'rt') as f: ...

  2. oracle 管理表空间

    表空间:是oracle数据库中最大的逻辑存储结构,与操作系统中的数据文件相对应,用于存储数据库中用户创建的所有内容 表空间>数据文件 4.1创建一个永久性表空间myspace create ta ...

  3. Python骚操作(一)

    1. 交换变量值 2. 将列表中所有元素组合成字符串 3. 查找列表中频率最高的值 4. 检查连个字符串是不是由相同字母不同顺序组成 5. 反转字符串 6. 反转列表 7. 转置二维数组 8. 链式比 ...

  4. Ubuntu环境下Postgres源码文件编译安装步骤

    step1:官网下载postgres源码 URL:https://www.postgresql.org/ftp/source/ step2:解压源码文件 tar -zxvf postgresql-12 ...

  5. SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: InlineParameterMap

    <select id="getResByName" resultClass="Resources" parameterClass="java.l ...

  6. HTML_案例(首页制作)

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

  7. Docker学习の更改Docker的目录

    一.更改虚拟磁盘的目录 虚拟机的默认存储位置是C:\Users\Administrator\.docker\machine\machines ,后期docke镜像文件会不断增加,为了给系统盘减负,最好 ...

  8. arm-linux-readelf 的使用

    1. 读 elf 文件开始的文件头部 [arm@localhost gcc]$ arm­linux­readelf ­h hello ELF Header: Magic:   7f 45 4c 46 ...

  9. Python学习笔记(五)——异常处理

    Python 异常总结 异常名称 解释 AssertionError 断言语句(assert)失败:当assert关键字后边的条件为假时,程序将抛出该异常,一般用于在代码中置入检查点 OSError ...

  10. Pipe进程之间的通信

    #_author:来童星#date:2019/12/11#Pipefrom multiprocessing import Process, Pipedef f(conn): conn.send([42 ...