-
Notifications
You must be signed in to change notification settings - Fork 0
/
10276.cpp
49 lines (42 loc) · 875 Bytes
/
10276.cpp
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
/*
**************************************************************
* Author : Bemen Girgis
* Contact : [email protected]
* Problem : ##### UVA
* Link : https://onlinejudge.org/external/###/p#####.pdf
**************************************************************
* Approach:
**************************************************************
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
bool is_square(int val) {
int sqr = sqrt(val);
return val == sqr * sqr;
}
int arr[51];
int ans;
int n;
void place(int val) {
for (int i = 0; i < n; ++i) {
if (!arr[i] || is_square(arr[i] + val)) {
arr[i] = val; ++ans;
place(val + 1);
break;
}
}
}
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
memset(arr, 0, sizeof(arr)); ans = 0;
scanf("%d", &n);
place(1);
printf("%d\n", ans);
}
return 0;
}