-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChefAndSquares.java
More file actions
51 lines (38 loc) · 1.07 KB
/
ChefAndSquares.java
File metadata and controls
51 lines (38 loc) · 1.07 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
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by hardCode on 12/1/2016.
*/
public class ChefAndSquares {
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int t,k;
t=Integer.parseInt(br.readLine());
while(t-->0){
k=Integer.parseInt(br.readLine());
System.out.print(solve(k));
}
}
private static String solve(int k) {
StringBuilder sbr = new StringBuilder();
int start, ind;
if (k == 1) {
return "1";
}
start = k - (k / 2) + 1;
for (int i = 0; i < k; i++) {
ind = start;
for (int j = 0; j < k; j++) {
sbr.append(ind + " ");
ind++;
if (ind > k) ind = 1;
}
start++;
if (start > k) start = 1;
sbr.append("\n");
}
return sbr.toString();
}
}