프로그래밍/기타
백준 1977 완전제곱수 c++
윤꽁참감
2022. 6. 15. 10:10
반응형
#include <iostream>
using namespace std;
int main()
{
int min, max;
int cnt = 0;
int sum = 0;
int minimum = 10001;
ios::sync_with_stdio(0);
cin >> min >> max;
for (int j = 1; j <= 100; j++)
{
if (j*j >= min && j*j <= max)
{
sum += j*j;
cnt++;
}
if (j*j >= min && j*j <= max && minimum > j*j)
{
minimum = j*j;
}
}
if (cnt == 0)
{
cout << "-1";
return 0;
}
else cout << sum << '\n' << minimum;
}