【HDU

来源:互联网 发布:澳门网络博客 编辑:程序博客网 时间:2024/06/05 04:59

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 < 3 000000 ) .
Output
Output the result of (a)+ (a+1)+….+ (b)
Sample Input
3 100
Sample Output
3042

#include<cstdio>using namespace std ;typedef long long LL ;const int MAXN = 3000000 +10;const int MAXM = 1e6;const int mod  = 1e9+7 ;LL e[MAXN]; // 不能再开一个数组sum,否则爆内存void eular(){    for(int i=0;i<MAXN;i++) e[i]=i;    for(int i=2;i<MAXN;i++){         if(e[i]==i)         for(int j=i;j<MAXN;j+=i) e[j]=(LL)e[j]/i*(i-1);        e[i]=e[i-1]+e[i];    }}int main(){     eular();    int a,b;    while(scanf("%d%d",&a,&b)!=EOF){        printf("%lld\n",e[b]-e[a-1]);    }    return  0;}
原创粉丝点击