可见的点
思路 :
可以把题意转化为 \(1\le x,y\le N\), 求 \((x,y)\) 互质对. 然后拿图像就很好理解.
如果 \(x,y\) 不互质, 那么在这个射线从原点出发, 一定会遇见 \((\frac{x}{p},\frac{y}{p})\) . 就不会在过 \((x,y)\) 了.
很多情况下会遇到这种题的情况, 可以结合图像记忆.
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define VIT vector<int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 1e6 + 10;
int pri[N], cnt;
bool st[N];
int phi[N];
void init() {
phi[1] = 1;
for (int i = 2; i < N; ++i) {
if (!st[i]) {
pri[cnt++] = i;
phi[i] = i - 1;
}
for (int j = 0; pri[j] * i < N; ++j) {
st[pri[j] * i] = true;
if (i % pri[j] == 0) {
phi[pri[j] * i] = phi[i] * pri[j];
break;
}
phi[pri[j] * i] = phi[i] * (pri[j] - 1);
}
}
}
int main() {
IO;
init();
int T;
cin >> T;
for (int _ = 1; _ <= T; ++_) {
int n;
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; ++i) ans += phi[i];
ans = 2 * ans + 1;
cout << _ << ' ' << n << ' ' << ans << '\n';
}
return 0;
}