-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19_boj_2725.cpp
More file actions
53 lines (46 loc) · 1.13 KB
/
19_boj_2725.cpp
File metadata and controls
53 lines (46 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 1000
using namespace std;
int c,n;
int cnt=1;
int arr[MAX][MAX]={0,};
int gcdArray[MAX+1][MAX+1]={0,};
int GCD(int a, int b) { // using dynamic programming
if (b) {
if (gcdArray[b][a%b]==0)
return GCD(b, a%b);
else
return gcdArray[b][a%b];
} else {
return a;
}
}
int main() {
scanf("%d", &c);
for (int i=1; i<=MAX; i++) {
for (int j=1; j<=MAX; j++) {
gcdArray[i][j]=GCD(i,j);
}
}
for (int i=0; i<c; i++) {
scanf("%d", &n);
for (int x=1; x<=n; x++) {
for (int y=1; y<=n-x; y++) {
int gcd = gcdArray[x][y];
// printf("x : %d, y : %d, gcd : %d\n",x,y,gcd);
int nx=x/gcd;
int ny=y/gcd;
if ( arr[nx][ny] == 0 ) {
// printf("개이득 x : %d, y : %d, gcd : %d\n",x,y,gcd);
arr[nx][ny]=1;
cnt++;
}
}
}
printf("%d\n",cnt*2+1);
}
return 0;
}