URI Solution 1558 Sum of Two Squares -Solution in C, C++ | Dynamic Programming
URI Online Judge Solution | Dynamic Programming
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1558
Problem Name: URI Problem 1558 Sum of Two Squares
Problem Number : URI Problem 1558 Sum of Two Squares Solution
Online Judge : URI Online Judge Solution
Level: Dynamic Programming
Solution Language : C plus plus
URI Solution 1558 Sum of Two Squares Code in CPP:
#include <cstdio> #include <cmath> using namespace std; int main(int argc, char const *argv[]) { int n, i, j, s; bool b; while(scanf("%d", &n) == 1){ b = false; i = 0; j = sqrt(n); while(j >= i){ s = pow(i,2) + pow(j,2); if(s == n){ b = true; break; }else if(s < n){ i++; }else{ j--; } } if(b) puts("YES"); else puts("NO"); } return 0; }
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks