A cubic number is the result of using a whole number in a multiplication three times. For example, 3×3×3=273×3×3=27 so 2727 is a cubic number. The first few cubic numbers are 1,8,27,641,8,27,64 and 125125. Given an prime number pp. Check that if pp is a difference of two cubic numbers.
InputThe first of input contains an integer T (1≤T≤100)T (1≤T≤100) which is the total number of test cases.
For each test case, a line contains a prime number p (2≤p≤1012)p (2≤p≤1012).OutputFor each test case, output 'YES' if given pp is a difference of two cubic numbers, or 'NO' if not.Sample Input
10 2 3 5 7 11 13 17 19 23 29
Sample Output
NO NO NO YES NO NO NO YES NO NO
#include <iostream> #include <algorithm> #include <iomanip> #include <stdio.h> #include <set> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <sstream> #define ll long long const double pi= acos(-1.0); const double eps = 1e-7; using namespace std; ll t,n,k,r,l,m,x; ll a[1000000]; int main() { for(long long i=2;i<=1000000;i++) { a[i-1] = (i-1)*(i-1)+i*(i-1)+i*i; //if(i<=100) cout<<a[i-1]<<" "; } int t; cin>>t; while(t--) { cin>>k; int flag = 0; l = 1;r = 1000000; while(l<r) { ll mid = (l+r)/2; if(a[mid]>k) r = mid; else if(a[mid]<k) l = mid+1 ; else {flag = 1 ; break; } //cout<<" +++ "<<l<<" "<<r<<endl; } if(!flag) cout<<"NO"<<endl; else cout<<"YES"<<endl; } }