c++ 題目代碼很少,主要是如何在O(1)時間輸出滿足要求的這個數字。
注意數據範圍,本題選擇long。題目描述和代碼如下:
#include<iostream>
#include<math.h>
using namespace std;
int main(void)
{
long x;
cin>>x;
long temp = sqrt(x);
if(temp *(temp+1) > x)
cout<<(temp-1)<<endl;
else
cout<<temp<<endl;
return 0;
}