cggwz  

立方数(cubic)
Time Limit:1000ms Memory Limit:128MB

题目描述
lovechq定义了一类数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数。
现在给定一个数P,lovechq想要知道这个数是不是立方数。
当然你有可能随机输出一些莫名其妙的东西来骗分,因此lovechq有T次询问~

输入格式(cubic.in)
第一行一个数T,表示有T组数据。
接下来T行,每行一个数P。

输出格式(cubic.out)
输出T行,对于每个数如果是立方数,输出“YES”,否则输出“NO”。

输入样例
3
8
27
28

输出样例
YES
YES
NO

数据范围
对于30%的数据p<=100。
对于60%的数据p<=10^6。
对于100%的数据p<=10^18,T<=100。

解析:
是不是看到题就觉得很水。
事实上就是很水。
直接枚举就好了。
不过,我用了输入优化。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline long long read(){
    long long x = 0, f = 1;
    char ch = getchar();
    for(; ch<'0'||ch>'9'; ch = getchar()) if(ch == '-') f = -1;
    for(; ch>='0'&&ch<='9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    return x * f;
}
inline int iscubic(long long x){
    if(x<=0){
        return 0;
    }
    for(long long i=1;i*i*i<=x;i++){
        if(i*i*i==x){
            return 1;
        }
    }
    return 0;
}
int main(){
    freopen("cubic.in","r",stdin);
    freopen("cubic.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        long long n;
        n=read();
        if(iscubic(n)){
            printf("YES");
        }else{
            printf("NO");
        }
        if(T){
            printf("\n");
        }

    }
    return 0;
}
posted on 2017-10-30 18:11  cggwz  阅读(503)  评论(0)    收藏  举报