题解:P17413 「IXOI R3」时间复杂度分析

· · 题解

题目大意

给你一个数 n,

如果这个数大于5 \times 10^8,输出"O(1)"

如果这个数的平方大于5 \times 10^8,输出"O(n)"

如果这个数的平方不大于5 \times 10^8,输出"O(n^2)"

解法

很明朗,用基础if语句判断即可

#include<bits/stdc++.h>
using namespace std;
const long long c=5e8;
long long x;
int main(){
    cin>>x;
    if(x>c){
        cout<<"O(1)";
    }else{
        if(x*x<=c){
            cout<<"O(n^2)";
        }else{
            cout<<"O(n)";
        }
    }
}