题意: 求a到b之间的欧拉函数的平方的和。
思路:欧拉函数打表。
#define ll unsigned long long 要用 unsigned long long
AC代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define ll unsigned long long
using namespace std;
const int maxn=5000010;
ll phi[maxn];
void init(){
for(int i=2; i<=maxn; i++) phi[i]=0;
phi[1]=1;
for(int i=2; i<=maxn; i++) {
if(!phi[i]) {
for(int j=i; j<=maxn; j+=i) {
if(!phi[j]) phi[j]=j;
phi[j]=phi[j]/i*(i-1);
}
}
}
phi[0]=0;
for(int i=1; i<=maxn; i++) {
phi[i]=phi[i]*phi[i]+phi[i-1];
}
}
int main(){
init();
int t; scanf("%d",&t);
for(int cas=1; cas<=t; cas++) {
int a,b; scanf("%d%d",&a,&b);
printf("Case %d: %llu\n",cas,phi[b]-phi[a-1]);
}
return 0;
}