Skip to content

Commit be3b762

Browse files
authored
Create 633. Sum of Square Numbers (#506)
2 parents 0e91ab3 + 90f6763 commit be3b762

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

633. Sum of Square Numbers

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool judgeSquareSum(int c) {
4+
if (c<=2) return 1;
5+
while(c% 2==0) c/=2;
6+
if (c%4 ==3) return 0;
7+
int sqrt_c=sqrt(c);
8+
for (int k = 3; k<=sqrt_c; k+=4) {
9+
int exp = 0;
10+
if (c % k == 0) {
11+
while (c % k == 0) {
12+
exp++;
13+
c /= k;
14+
}
15+
if (exp %2 != 0)
16+
return 0;
17+
}
18+
}
19+
return c%4!=3;
20+
}
21+
};

0 commit comments

Comments
 (0)