c++ 题目代码很少,主要是如何在O(1)时间输出满足要求的这个数字。

注意数据范围,本题选择long。题目描述和代码如下:

2017校招真题1 星际穿越

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

相关文章:

  • 2021-08-01
  • 2022-12-23
  • 2021-10-05
  • 2021-05-16
  • 2021-06-29
  • 2021-11-21
  • 2022-12-23
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2022-02-15
  • 2022-12-23
  • 2021-12-10
  • 2021-09-01
  • 2021-07-25
相关资源
相似解决方案