LightOj1007 - Mathematically Hard(欧拉函数)
2016-10-24 19:14
323 查看
题目链接:http://lightoj.com/volume_showproblem.php?problem=1007
题意:给你两个数a和b,求他们之间所有数的欧拉值得平方和; [b]a and b (2 ≤ a ≤ b ≤ 5 * 106).[/b]
线性打表求值即可;
结果会爆long long,要用unsigned long long %llu形式;
View Code
题意:给你两个数a和b,求他们之间所有数的欧拉值得平方和; [b]a and b (2 ≤ a ≤ b ≤ 5 * 106).[/b]
线性打表求值即可;
结果会爆long long,要用unsigned long long %llu形式;
#include <stdio.h> #include <string.h> #include <algorithm> typedef unsigned long long LL; #define N 5000001 using namespace std; int f = {0}; LL ans = {0}; void Init() { for(int i=2; i<N; i++) { if(f[i]) continue; for(int j=i; j<N; j+=i) { if(!f[j]) f[j] = j; f[j] = f[j]/i*(i-1); } } ans[0] = 0; for(int i=1; i<N; i++) ans[i] = ans[i-1] + (LL)f[i]*f[i]; } int main() { Init(); int T, a, b, t = 1; scanf("%d", &T); while(T--) { scanf("%d %d", &a, &b); printf("Case %d: %llu\n", t++, ans[b]-ans[a-1]); } return 0; }
View Code
相关文章推荐
- LightOJ-1007-Mathematically Hard [欧拉函数]
- LightOj1007欧拉函数
- LightOJ - 1007 Mathematically Hard 欧拉函数快速打表+前缀和
- lightoj 1007 欧拉函数
- LightOJ1007---Mathematically Hard (欧拉函数)
- LightOJ 1007 Mathematically Hard 欧拉函数
- lightoj 1007 - Mathematically Hard 欧拉函数
- lightoj 1007 欧拉函数
- lightoj 1007 - Mathematically Hard 欧拉函数
- LIGHTOJ 1007 – MATHEMATICALLY HARD【欧拉函数】
- LightOJ 1007 欧拉函数
- Lightoj1007【欧拉函数-素数表】
- LightOJ - 1370 Bi-shoe and Phi-shoe【欧拉函数的性质】
- LightOJ 1007 Mathematically Hard
- Lightoj 1007 - Mathematically Hard
- lightoj 1370 Bi-shoe and Phi-shoe 【欧拉函数应用】
- lightoj1370欧拉函数/素数筛
- Lightoj 1007
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数
- lightoj 1007