Files
python/TangDou/AcWing/Math/201_4.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

45 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
using namespace std;
typedef long long LL;
//最大公约数,辗转相除法
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
//快读
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int N = 2010;
int n, m, a[N][N];
void init() {
for (int i = 1; i <= 1000; i++) //互质,赋值为1
for (int j = 1; j <= 1000; j++)
if (gcd(i, j) == 1) a[i][j] = 1;
for (int i = 1; i <= 1000; i++) //二维前缀和
for (int j = 1; j <= 1000; j++)
a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
}
int main() {
init();
int m = read();
for (int i = 1; i <= m; i++) {
n = read();
printf("%d %d %d\n", i, n, a[n][n] + 2); //加上(1,0),(0,1)两个点
}
return 0;
}