/*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 Input3 100 |
Sample Output3042 |
|
Source2009 multi-university Training Contest 1-host by Tju |
Recommendgaojie |
The Euler function (linear sieve Euler functions)