您的位置:首页 > 其它

Lightoj 1007

2016-06-05 21:08 375 查看
题意: 求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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  lightoj