2017校招真題1 星際穿越

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

發佈了28 篇原創文章 · 獲贊 20 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章