-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path633.java
38 lines (38 loc) · 1.13 KB
/
633.java
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
__________________________________________________________________________________________________
sample 0 ms submission
public class Solution {
public boolean judgeSquareSum(int c) {
for (int i = 2; i * i <= c; i++) {
int count = 0;
if (c % i == 0) {
while (c % i == 0) {
count++;
c /= i;
}
if (i % 4 == 3 && count % 2 != 0)
return false;
}
}
return c % 4 != 3;
}
}
__________________________________________________________________________________________________
sample 31644 kb submission
class Solution {
public boolean judgeSquareSum(int c) {
int l = 0, r = (int)Math.sqrt(c);
while(l <= r){
int num = l * l + r * r;
if(num == c){
return true;
}
if(num < c){
l = l + 1;
}else{
r = r - 1;
}
}
return false;
}
}
__________________________________________________________________________________________________