zoukankan      html  css  js  c++  java
  • LightOJ 1370 Bi-shoe and Phi-shoe

     1 /*
     2  LightOJ 1370 Bi-shoe and Phi-shoe
     3  http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370
     4  数论 欧拉函数
     5  坑点是答案会爆int!!!!
     6  */
     7 #include <cstdio>
     8 #include <algorithm>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <vector>
    12 #include <queue>
    13 #include <iostream>
    14 #include <map>
    15 #include <set>
    16 //#define test
    17 using namespace std;
    18 const int Nmax=1e6+5e5;//Nmax一定要大于1e6否则会找不到答案
    19 int phi[Nmax];
    20 int prime[Nmax];
    21 int is_prime[Nmax];
    22 int prime_cnt;
    23 void get()
    24 {
    25     phi[1]=1;
    26     for(int i=2;i<Nmax;i++)
    27         is_prime[i]=1;
    28     for(long long i=2;i<Nmax;i++)
    29     {
    30         if(is_prime[i])
    31         {
    32             prime[++prime_cnt]=i;
    33             phi[i]=i-1;
    34         }
    35         for(int j=1;j<=prime_cnt;j++)
    36         {
    37             if(i*prime[j]>=Nmax)
    38                 break;
    39             is_prime[i*prime[j]]=0;
    40             if(i%prime[j]==0)
    41             {
    42                 phi[i*prime[j]]=phi[i]*prime[j];
    43                 break;
    44             }
    45             else
    46                 phi[i*prime[j]]=phi[i]*(prime[j]-1);
    47         }
    48     }
    49 }
    50 int main()
    51 {
    52     #ifdef test
    53     #endif
    54     get();    
    55     phi[1]=0;//此题要求phi[1]=0;
    56     //for(int i=1;i<Nmax;i++)
    57     //{
    58         //num[i].id=i;
    59         //num[i].val=phi[i];
    60     //}
    61     //sort(num+1,num+Nmax);
    62     //for(int i=1;i<=40;i++)
    63     //{
    64         //printf("phi[%d]:%d
    ",i,phi[i]);
    65     //}
    66     int t,n;
    67     scanf("%d",&t);
    68     for(int ttt=1;ttt<=t;ttt++)
    69     {
    70         scanf("%d",&n);
    71         long long ans=0LL;//此题一大坑点,ans会爆int
    72         int a;
    73         for(int i=1;i<=n;i++)
    74         {
    75             scanf("%d",&a);
    76             for(int j=a+1;j<Nmax;j++)//强力减枝!
    77             {
    78                 if(phi[j]>=a)
    79                 {
    80                     ans+=1LL*j;
    81                     break;
    82                 }
    83             }
    84         }
    85         printf("Case %d: %lld Xukha
    ",ttt,ans);
    86     }
    87     return 0;
    88 }
  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/BBBob/p/6762566.html
Copyright © 2011-2022 走看看