#7~10 TLE 求助
查看原帖
#7~10 TLE 求助
542128
liyixin0514楼主2024/11/13 15:31

时间复杂度应该是对的,然鹅 TLE 了,不知道为什么,求助/bx

难道是常数太大?

#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
typedef long long ll;
namespace poetry {
	#define isdigit(x) (x>='0'&&x<='9')
    #define gc getchar_unlocked
    template <typename T>
    void read(T &x) {
        x=0;
        char ch=gc();
        for(;!isdigit(ch);ch=gc());
        for(;isdigit(ch);ch=gc()) x=(x<<3)+(x<<1)+(ch^48);
    }
    constexpr int N=1e5+7,V=4e3;
    int n;
    ll x;
    int can[V];
    bool vi[V+5];
    void init() {
        rep(i,2,V) {
            if(!vi[i]) {
                can[++can[0]]=i;
                for(int j=i;i*j<=V;j+=i) vi[i*j]=1;
            }
        }
    }
    ll _pow3(ll x) { return x*x*x; }
    ll _pow2(ll x) { return x*x; }
    bool sqrt3(ll x) { return x==_pow3(round(cbrt(x))); }
    bool sqrt2(ll x) { return x==_pow2(round(sqrt(x))); }
    void main() {
        init();
		read(n);
        rep(i,1,n) {
			read(x);
            ll y=x;
            bool ans=1;
            for(int j=1;j<=can[0];j++) {
                if(1ll*can[j]*can[j]*can[j]*can[j]*can[j]>y) break; 
                int cnt=0;
                while(x%can[j]==0) x/=can[j], ++cnt;
                if(cnt==1) { ans=0; break; }
            }
            if(ans&&(sqrt3(x)||sqrt2(x))) puts("yes");
            else puts("no");
        }
    }
}
int main() {
    poetry :: main();
}
2024/11/13 15:31
加载中...