/*The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4299 Accepted Submission(s): 1788 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 2009 Multi-University Training Contest 1 - Host by TJU Recommend gaojie | We have carefully selected several similar problems for you: 2825 2822 2821 2820 2823 */ #include<stdio.h> __int64 e[3000010]; int main() { int i, j, k, n, m; for(i = 1; i <= 3000005; ++i) e[i] = i; for(i = 2; i <= 3000005; ++i) { if(e[i] == i) for(j = i; j <= 3000005; j += i) e[j] = e[j]/i*(i-1); } for(i = 2; i <= 3000005; ++i) e[i] += e[i-1]; while(scanf("%d%d", &n, &m) != EOF) { printf("%I64d\n", e[m] - e[n-1]); } return 0; }
题意:给出a和b求出a到b中所有数的欧拉函数的和。
思路:就是最基本的欧拉函数模板题,要根据欧拉函数的定义e【i】=i * (1 - 1 / p1) * (1 - 1 / p2) ......* (1 - 1 / pn) ,其中pn为i的质因数。