C++:: 프로그래머스 < 정수 제곱근 판별 >

jahlee·2023년 8월 6일
0

프로그래머스_Lv.1

목록 보기
57/75
post-thumbnail

제곱근이라면 +1한값의 제곱을 반환해주는 문제이다. 아니라면 -1 반환

#include <string>
#include <vector>
#include <cmath>
using namespace std;

long long solution(long long n) {
    long long x = sqrt(n);
    if (x*x == n) return pow(x+1,2);
    return -1;
}

0개의 댓글