Hangzhou Electric 2824--the Euler function (Euler functions)

Source: Internet
Author: User

The Euler function

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4559 Accepted Submission (s): 1902


Problem DescriptionThe Euler function phi is a important kind of function in number theory, (n) represents the amount of The numbers which is smaller than N and coprime to n, and this function have a lot of beautiful characteristics. Here comes a very easy question:suppose is given a, B, try to calculate (a) + (a+1) +....+ (b)

Inputthere is several test cases. Each line has a integers a, b (2<a<b<3000000).

Outputoutput The result of (a) + (a+1) +....+ (b)

Sample INPUT3 100

Sample Output3042

Source2009 multi-university Training Contest 1-host by Tju

Recommendgaojie | We have carefully selected several similar problems for you:2818 2825 2817 2822 2821
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;Const intN =3000010;intPrime[n], isprime[n];intPhi[n];voidGet_phi () {intI, j, cnt =0;  for(i =2; i < N; i++){        if(Isprime[i] = =0) {prime[cnt++] =i; Phi[i]= I1; }             for(j =0; J < CNT && I*prime[j] < N; J + +) {Isprime[i*prime[j]]=1; if(i%prime[j]==0) Phi[i*prime[j]]=phi[i]*Prime[j]; ElsePhi[i*prime[j]]=phi[i]* (prime[j]-1); }     }     }  intMain () {intA, B;    Get_phi ();  while(~SCANF ("%d%d", &a, &b)) {Long Longsum =0;  for(inti = A; I <= b; i++) Sum+=Phi[i]; cout<< sum <<Endl; }    return 0;}

Hangzhou Electric 2824--the Euler function (Euler functions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.