zoukankan      html  css  js  c++  java
  • HDUOJ-----2824The Euler function

    The Euler function

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 3284    Accepted Submission(s): 1350


    Problem Description
    The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+....+ (b)
     
    Input
    There are several test cases. Each line has two integers a, b (2<a<b<3000000).
     
    Output
    Output the result of (a)+ (a+1)+....+ (b)
     
    Sample Input
    3 100
     
    Sample Output
    3042
     
    Source
     
    Recommend
     
    欧拉函数....
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 const int maxn=3000001;
     4 __int64 phi[maxn];
     5 int main()
     6 {
     7     int st,en,i,j;
     8         for(i=1;i<maxn;i++)
     9             phi[i]=i;
    10         for(i=2;i<maxn;i+=2)
    11             phi[i]/=2;
    12         for(i=3;i<maxn;i+=2)
    13         {
    14             if(phi[i]==i)
    15             {
    16                 for(j=i;j<maxn;j+=i)
    17                 {
    18                     phi[j]=phi[j]/i*(i-1);      /*from left to right*/
    19                 }
    20             }
    21         }
    22     while(scanf("%d%d",&st,&en)!=EOF)
    23     {
    24     
    25         __int64 ans=0;
    26         for(i=st;i<=en;i++)
    27         {
    28             ans+=phi[i];
    29         }
    30         printf("%I64d
    ",ans);
    31     }
    32 
    33     return 0;
    34 }
    View Code
  • 相关阅读:
    第一课 进阶高手的大门
    Codeforces Round #363 (Div. 2) C. Vacations
    HDU 5718 Oracle
    A
    Fibonacci数的后9位
    UESTC 982质因子分解
    UESTC149 解救小Q
    UESTC93 King's Sanctuary
    HDU 4857 逃生
    L1-006. 连续因子
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3576886.html
Copyright © 2011-2022 走看看