zoukankan      html  css  js  c++  java
  • uva10820 send a table (nlogn求1-n欧拉函数值模版

    //重点就是求1-n的欧拉函数啦,重点是nlogn求法的版

    //大概过程类似于筛选法求素数

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<queue>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<string>
    12 
    13 using namespace std;
    14 
    15 int n;
    16 int phi[50001];
    17 int f[50001];
    18 
    19 int main(){
    20     memset(phi,0,sizeof(phi));
    21     memset(f,0,sizeof(f));
    22     phi[1]=1;
    23     for (int i=2;i<=50000;i++){
    24             if (phi[i]==0){
    25                     for (int j=i;j<=50000;j+=i){
    26                             if (phi[j]==0) phi[j]=j;
    27                             phi[j]=phi[j]/i*(i-1);
    28                     }
    29             }
    30     }
    31     for (int i=1;i<=50000;i++) f[i]=f[i-1]+phi[i];
    32     while (scanf("%d",&n)==1){
    33             if (n==0) return 0;
    34             printf("%d
    ",f[n]*2-1);
    35     }
    36     return 0;
    37 }
    38 /*
    39 2
    40 5
    41 0
    42 */
    View Code
  • 相关阅读:
    linux中nc命令
    Centos6.5 安装zabbix3(收藏,非原创)
    紀念
    算法学习资源收集
    一道奇怪的求和题
    P5717 题解
    P1424 刷题记录
    P1888 题解
    P1422 刷题记录
    P1055 题解
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4647038.html
Copyright © 2011-2022 走看看