HDU
来源:互联网 发布:天谕萝莉捏脸数据小茗 编辑:程序博客网 时间:2024/05/22 13:48
给定的数是立方质数
这里满足的条件的是 ( b+1 ) ^ 3 - b ^ 3 = p ;
又有 a^3 - b^3 = ( a^2 + b^2 + a*b ) * ( a-b) ;
可以解方程得到答案
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#include <sstream>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;const int maxn = 10000000 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;int n;int main() { ios::sync_with_stdio(0); cin >> n; ll p; while(n--) { cin >> p; int ff = 1; ll t = (ll)9- (ll)12*((ll)1-p); ll tt = sqrt(t); if(tt*tt != t) ff = 0; if( (tt-3) % 6 != 0) ff = 0; if(ff) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0;}