zoukankan      html  css  js  c++  java
  • HDU——T 2824 The Euler function

    http://acm.hdu.edu.cn/showproblem.php?pid=2824

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


    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
     
     
    欧拉函数表。前缀和
     1 #include <algorithm>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 #define LL long long
     7 const int N(3000233);
     8 LL a,b,phi[N];
     9 
    10 void All_phi()
    11 {
    12     for(int i=1;i<=N;i++)
    13       phi[i]=i;
    14     for(int i=2;i<=N;i++)
    15       if(phi[i]==i)
    16         for(int j=i;j<=N;j+=i)
    17           phi[j]=phi[j]/i*(i-1);
    18 }
    19 
    20 int main()
    21 {
    22     All_phi();
    23     for(int i=1;i<=N+1;i++) phi[i]=phi[i-1]+phi[i];
    24     for(;scanf("%d%d",&a,&b)!=EOF;)
    25         printf("%I64d
    ",phi[b]-phi[a-1]);
    26     return 0;
    27 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    缓冲区
    4.9
    JDBC连接
    3.31
    BizTalk框架概述
    不通过SPS对象模型更改文档扩展字段的方法
    asdfasdf
    设计模式介绍
    Multiple Checkbox Items In A DataGrid Introduction
    Factory Method
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7306564.html
Copyright © 2011-2022 走看看