zoukankan      html  css  js  c++  java
  • HDU-2824 The Euler function(欧拉函数)

    The Euler function

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


    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 "bits/stdc++.h"
     2 using namespace std;
     3 typedef long long LL;
     4 const int MAX=3e6+5;
     5 int phi[MAX];
     6 void eular(){
     7     int i,j;
     8     for (i=1;i<MAX;i++) phi[i]=i;
     9     for (i=2;i<MAX;i+=2) phi[i]/=2;
    10     for (i=3;i<MAX;i+=2){
    11         if (phi[i]==i)
    12             for (j=i;j<MAX;j+=i)
    13                 phi[j]=phi[j]/i*(i-1);
    14     }
    15 }
    16 int main(){
    17     freopen ("euler.in","r",stdin);
    18     freopen ("euler.out","w",stdout);
    19     int i,j;
    20     eular();
    21     LL x,y,ans;
    22     while (~scanf("%lld%lld",&x,&y)){
    23         for (i=x,ans=0;i<=y;i++) ans+=(LL)phi[i];
    24         printf("%lld
    ",ans);
    25     }
    26     return 0;
    27 }
    未来是什么样,未来会发生什么,谁也不知道。 但是我知道, 起码从今天开始努力, 肯定比从明天开始努力, 要快一天实现梦想。 千里之行,始于足下! ——《那年那兔那些事儿》
  • 相关阅读:
    C#学习笔记-代理模式
    SqlDbx连接oracle
    C# 连接oracle,用32位client和64位Client,可能导致结果不同
    PHP&Java 调用C#的WCF
    DevExpress GridControl 控件二表连动
    SSAS 非重复计数
    Corn 表达式
    C# 实现Tree,包含parentId和children
    jsfiddle.net上的记录
    【慕课网实战】Spark Streaming实时流处理项目实战笔记十二之铭文升级版
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7664005.html
Copyright © 2011-2022 走看看