求区间欧拉函数和
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 3000005; 7 long long e[maxn + 10]; 8 9 void init() { 10 e[1] = 1; 11 for(int i = 2; i < maxn; i++) e[i] = i; 12 for(int i = 2; i < maxn; i++) 13 if(e[i] == i) 14 for(int j = i; j < maxn; j += i) 15 e[j] = e[j] / i * ( i - 1); 16 for(int i = 2; i < maxn; i++) { 17 e[i] += e[i - 1]; 18 } 19 } 20 21 int main() { 22 init(); 23 int n, m; 24 while(EOF != scanf("%d %d",&n, &m)) { 25 printf("%I64d\n", e[m] - e[n - 1]); 26 } 27 return 0; 28 }