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;
}