From e967ea8a8d35b9f21d5c7f976d9019f73d46b077 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Thu, 19 Sep 2024 20:32:57 -0300 Subject: [PATCH] Solve Sum of Two Squares in c --- solutions/beecrowd/1558/1558.c | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 solutions/beecrowd/1558/1558.c diff --git a/solutions/beecrowd/1558/1558.c b/solutions/beecrowd/1558/1558.c new file mode 100644 index 00000000..192d2384 --- /dev/null +++ b/solutions/beecrowd/1558/1558.c @@ -0,0 +1,35 @@ +#include +#include +#include + +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; +}