-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
633.py
34 lines (34 loc) · 1.1 KB
/
633.py
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
__________________________________________________________________________________________________
sample 32 ms submission
class Solution:
def judgeSquareSum(self, c: int) -> bool:
i = 2
while i * i < c:
counter = 0
while 0 == c % i:
if 3 == i % 4:
counter += 1
else:
pass
c //= i
if 0 != counter and 0 != counter % 2:
return False
else:
i += 1
return 3 != c % 4
__________________________________________________________________________________________________
sample 12888 kb submission
class Solution:
def judgeSquareSum(self, c: int) -> bool:
if c == 0:
return True
import math
for i in range(c):
if i*i <= c:
tmp = math.sqrt(c-i*i)
if tmp == int(tmp):
return True
else:
break
return False
__________________________________________________________________________________________________