思路很简单,也不知道为什么想不到,总之现在必须是会了。
先开平方根,强制类型转换,再乘回去,相等就输出,不相等就+1在输出,就这么粗暴。
#include <iostream>
using namespace std;
#include <cmath>
int sf(int x0)
{
int x=sqrt(x0);
if(x*x==x0) return x0;
else return (x+1)*(x+1);
}
int main()
{
int n;
cin>>n;
int a=sf(n);
cout<<a;
}