题目链接:https://www.nowcoder.com/acm/contest/141/H 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be so…
https://blog.csdn.net/Lytning/article/details/24432651 记牢通式 =x((p1-1)/p1) * ((p2-1)/p2)....((pn-1)/pn) 求一个整数的欧拉函数: int eular(int n){ int res = n, x = n; for(int i = 2; i*i <= x; i++){ if(x % i == 0){ //是其中的一个质因数 res = res/i*(i-1);//保证为整数 且不会溢出 whi…
欧拉筛法可以以\(O(n)\)的时间,空间复杂度求出\(1-n\)范围内的所有质数. 其核心思想是每个合数仅会被其最小的质因数筛去一次. See this website for more details. ```cpp #include <iostream> #include <cstdio> using namespace std; const int MAXN(1000001); int n_prime(0); bool not_prime[MAXN]; int prime[…