-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMath.java
More file actions
executable file
·33 lines (30 loc) · 807 Bytes
/
Copy pathGameMath.java
File metadata and controls
executable file
·33 lines (30 loc) · 807 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
public class GameMath{
public static boolean[] sumOfTwoDistinctSquares(int n) {
boolean isSumOfSquares[] = new boolean[n];
int i = 1;
int j = i+1;
while((i*i + j*j) < n) {
isSumOfSquares[(i*i + j*j)] = true;
j++;
if((i*i + j*j) >= n) {
i++;
j = i+1;
}
}
return isSumOfSquares;
}
public static boolean[] subtractSquare(int n) {
boolean truthValues[] = new boolean[n];
for(int i = 1; i < n; i++) {
int move = 1;
while((i - move*move) >= 0) {
if(!truthValues[(i - move*move)]) {
truthValues[i] = true;
break;
}
move++;
}
}
return truthValues;
}
}