【欧拉函数】【数论】17.6.2 数学题 题解
2017-06-02 19:28
183 查看
#include <iostream> #include <cstdio> #include <cstring> #define clr(a) memset(a, 0, sizeof(a)) #define LL long long #ifdef win32 #define AUTO "%I64d" #else #define AUTO "%lld" #endif using namespace std; const int MAXN = 10000005; int t,n,ptot; int primes[MAXN]; bool isnot[MAXN]; template <class T> inline void read(T &x) { int flag = 1; x = 0; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag; } LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a%b); } inline void linear_sieve(int n) { isnot[1] = true; for(register int i = 2; i <= n; i++) { if(!isnot[i]) primes[ptot++] = i; for(register int t = 0; t < ptot; t++) { int j = primes[t]*i; if(j > n) break; isnot[j] = true; if(!(i%primes[t])) break; } } } inline LL Calc_Fn(int N) { LL ans = 0; for(LL i = 1; i <= N; i++) ans += N/gcd(i,N); return ans; } int main() { freopen("maths.in","r",stdin); freopen("maths.out","w",stdout); linear_sieve(10000000); read(t); while(t--) { LL ans = 0; read(n); printf(AUTO"\n", Calc_Fn(n)); } return 0; }
相关文章推荐
- POJ 2154 Color(组合数学-波利亚计数,数论-欧拉函数,整数快速幂)
- POJ 2154 Color(组合数学-波利亚计数,数论-欧拉函数,整数快速幂)
- HDU 1695 GCD (数论-整数和素数,欧拉函数,组合数学-容斥原理)
- [数论-欧拉函数的应用]NEFU 1115
- hdu 4135 Co-prime (组合数学:容斥定理+欧拉函数)
- 【BZOJ-4173】数学 欧拉函数 + 关于余数的变换
- POJ2407 ZOJ1906 UVA10229 Relatives【欧拉函数+数论】
- 【基础数论】十分钟学会计算欧拉函数
- 欧拉函数 算法摘记 数论
- 数论:欧拉函数 uva 10820
- 数论线性筛总结 (素数筛,欧拉函数筛,莫比乌斯函数筛,前n个数的约数个数筛)
- ACM: 数学规律题 数论题 hdoj 1021
- 数论一(hdoj 简单数学题、推理题)
- 【数论】【枚举约数】【欧拉函数】bzoj2705 [SDOI2012]Longge的问题
- 51nod 序列变换 [容斥原理+莫比乌斯函数]【数论+组合数学】
- 数论之 素因子分解,素数筛选法,欧拉函数和扩展欧几里得算法 (整理)
- 数学修炼笔记——组合&数论&博弈
- HDU4335 What is N? [数论(欧拉函数)]
- hdu 2588 GCD [欧拉函数]【数论】*
- [SDOI2012]Longge的问题(数论,欧拉函数)