Lightoj 1007
2016-06-05 21:08
375 查看
题意: 求a到b之间的欧拉函数的平方的和。
思路:欧拉函数打表。
#define ll unsigned long long 要用 unsigned long long
AC代码:
思路:欧拉函数打表。
#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 1067 Combinations 组合数取模
- LightOJ 1004 - Monkey Banana Problem
- LightOJ 1011 - Marriage Ceremonies
- LightOJ 1033 - Generating Palindromes
- LightOJ 1047 - Neighbor House
- LightOJ 1013 - Love Calculator
- LightOJ 1122 - Digit Count
- LightOJ1112——Curious Robin Hood
- lightoj-1427:Substring Frequency
- lightoj 1007Mathematically Hard (欧拉函数水题)
- lightoj1213 - Fantasy of a Summation
- lightoj1214 - Large Division
- lightoj1220Mysterious Bacteria
- lightoj1234Harmonic Number
- lightoj1236Pairs Forming LCM
- lightoj1245Harmonic Number (II)
- lightoj1259 - Goldbach`s Conjecture(水题)
- lightoj1282 - Leading and Trailing(水题)
- lightoj1336Sigma Function(dfs打表或容斥)
- lightoj1341Aladdin and the Flying Carpet(分解质因数+dfs)