프로그래머스 - 정수 제곱근 판별

well-life-gm·2021년 11월 6일
0

프로그래머스

목록 보기
39/125

프로그래머스 - 정수 제곱근 판별

cmath 라이브러리의 pow, powl, sqrt를 자주 이용해야겠다. (매번 직접 구현했는데;)

제곱근의 제곱이 원래 수랑 다르면 -1을 리턴해주면 된다.

#include <string>
#include <vector>
#include <cmath>

using namespace std;

long long solution(long long n) {
    long long answer = sqrt(n);
    return powl(answer, 2) == n ? powl(answer + 1, 2) : -1;
}
profile
내가 보려고 만든 블로그

0개의 댓글