-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet_Min_Squares.java
More file actions
39 lines (36 loc) · 815 Bytes
/
Copy pathGet_Min_Squares.java
File metadata and controls
39 lines (36 loc) · 815 Bytes
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
public class GetMinSquares {
/**
* Author: Gaurav Shrivastava
*/
public static void main(String[] args) {
int arr[] = new int [1000001];
arr[0] = 0;
arr[1] = 1;
arr[2] = 2;
arr[3] = 3;
for (int i = 4; i < arr.length; i++) {
int k = i - (int)Math.pow((int)Math.sqrt(i), 2);
arr[i] = 1 + arr[k];
}
for (int i = 0; i < 11; i++) {
System.out.print(" " + arr[i]);
}
System.out.println();
for (int i = 10; i < 21; i++) {
System.out.print(" " + arr[i]);
}
System.out.println();
for (int i = 20; i < 31; i++) {
System.out.print(" " + arr[i]);
}
System.out.println();
for (int i = 30; i < 41; i++) {
System.out.print(" " + arr[i]);
}
System.out.println();
for (int i = 40; i < 51; i++) {
System.out.print(" " + arr[i]);
}
System.out.println();
}
}