The Euler function (linear sieve Euler functions)

Source: Internet
Author: User

/*Test Instructions: (n) indicates how many of the numbers are less than N and n coprime, gives you two numbers, a, A + (a+1) + (a+2) +......+b; Initial thinking: violence, play the table # give up: Played more than 10 minutes did not finish # Improved: Euler function: specific proof see PO Master's Blog ^0^ #超时: Here the direct use of Euler function violence or not, with the linear sieve Euler function, where the sum of the explosion int, to use a long long*/#include<bits/stdc++.h>#definell Long Longusing namespacestd;/************************** Euler function template *****************************///selection method to play the European pull function table#defineMax 3000010intEuler[max];voidInit () {euler[1]=1;  for(intI=2; i<max;i++) Euler[i]=i;  for(intI=2; i<max;i++)        if(euler[i]==i) for(intj=i;j<max;j+=i) euler[j]=euler[j]/i* (I-1);//Division first to prevent overflow of intermediate data}/************************** Euler function template *****************************/intb;intMain () {//freopen ("In.txt", "R", stdin);Init ();  while(SCANF ("%d%d", &a,&b)! =EOF) {ll cur=0;  for(inti=a;i<=b;i++) {cur+=Euler[i]; } printf ("%lld\n", cur); }    return 0;}

The Euler function
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 224 Accepted Submission (s): 124
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).
Output output The result of (a) + (a+1) +....+ (b)
Sample Input
3 100
Sample Output
3042
Source2009 multi-university Training Contest 1-host by Tju
Recommendgaojie

The Euler function (linear sieve 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.