简单题
View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
#define maxn 1005
int n;
int f[maxn][maxn];
int gcd(int x, int y)
{
if (!x || !y)
return x > y ? x : y;
for (int t; t = x % y; x = y, y = t)
;
return y;
}
int main()
{
//freopen("t.txt", "r", stdin);
for (int i = 1; i <= 1000; i++)
for (int j = 1; j <= 1000; j++)
if (gcd(i, j) == 1)
f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1] + 1;
else
f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1];
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d", &n);
printf("%d %d %d\n", i + 1, n, f[n][n] + 2);
}
return 0;
}