其他分享
首页 > 其他分享> > Codeforces 1490C Sum of Cubes

Codeforces 1490C Sum of Cubes

作者:互联网

C. Sum of Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

You are given a positive integer xx. Check whether the number xx is representable as the sum of the cubes of two positive integers.

Formally, you need to check if there are two integers aa and bb (1≤a,b1≤a,b) such that a3+b3=xa3+b3=x.

For example, if x=35x=35, then the numbers a=2a=2 and b=3b=3 are suitable (23+33=8+27=3523+33=8+27=35). If x=4x=4, then no pair of numbers aa and bb is suitable.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow.

Each test case contains one integer xx (1≤x≤10121≤x≤1012).

Please note, that the input for some test cases won't fit into 3232-bit integer type, so you should use at least 6464-bit integer type in your programming language.

Output

For each test case, output on a separate line:

You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

Example input Copy
7
1
2
4
34
35
16
703657519796
output Copy
NO
YES
NO
NO
YES
YES
YES
Note

The number 11 is not representable as the sum of two cubes.

The number 22 is represented as 13+1313+13.

The number 44 is not representable as the sum of two cubes.

The number 3434 is not representable as the sum of two cubes.

The number 3535 is represented as 23+3323+33.

The number 1616 is represented as 23+2323+23.

The number 703657519796703657519796 is represented as 57793+7993357793+79933.

 

确定好两个数的范围, 预处理一下, 用set 插入查找

//2021-03-14 19:56:14
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int T;
set<ll> rec;


int main(){
    for(int i = 1; i <= 1e4; i++){
        rec.insert((ll)i*i*i);
    }
    scanf("%d", &T);
    while(T--){
        ll x;
        scanf("%lld", &x);
        bool ok = 0;
        for(auto i: rec){
            if(rec.find(x-i) != rec.end()) ok = 1;
        }
        if(ok) printf("YES\n");
        else printf("NO\n");

    }

    return 0;
}

 

 

标签:Cubes,Codeforces,number,two,test,integer,1490C,include,YES
来源: https://www.cnblogs.com/sineagle/p/14533952.html