Skip to content

Commit

Permalink
Solve Sum of Two Squares in c
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Sep 19, 2024
1 parent adf897c commit e967ea8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions solutions/beecrowd/1558/1558.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <math.h>
#include <stdint.h>
#include <stdio.h>

int has_square(int32_t n) {
int32_t limit = sqrt(n);

if (n < 0) {
return 0;
}

for (int32_t i = 0; i <= limit; i++) {
for (int32_t j = 0; j <= limit; j++) {
if (pow(i, 2) + pow(j, 2) == n) {
return 1;
}
}
}

return 0;
}

int main() {
int32_t n;

while (scanf("%ld", &n) != EOF) {
if (has_square(n)) {
puts("YES");
} else {
puts("NO");
}
}

return 0;
}

0 comments on commit e967ea8

Please sign in to comment.