hdu 6216 A Cubic number and A Cubic Number

ゝ一纸荒年。 2022-06-08 07:06 254阅读 0赞

A Cubic number and A Cubic Number

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 438 Accepted Submission(s): 237

Problem Description

A cubic number is the result of using a whole number in a multiplication three times. For example, 3×3×3=27 so 27 is a cubic number. The first few cubic numbers are 1,8,27,64 and 125. Given an prime number p. Check that if p is a difference of two cubic numbers.

Input

The first of input contains an integer 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).

Output

For each test case, output ‘YES’ if given p is a difference of two cubic numbers, or ‘NO’ if not.

Sample Input

  1. 10
  2. 2
  3. 3
  4. 5
  5. 7
  6. 11
  7. 13
  8. 17
  9. 19
  10. 23
  11. 29

Sample Output

  1. NO
  2. NO
  3. NO
  4. YES
  5. NO
  6. NO
  7. NO
  8. YES
  9. NO
  10. NO
  11. 题目大意:
  12. 题目的意思就是说,给你一个素数P,问是否有两个数的立方差等于p,如果有输出YES,没有输出NO
  13. 题目解析:
  14. 由题目可以得到,由于a^3-b^3=(a-b)(a^2+b^2+ab) 所以(a-ba-b只有等于1a^3-b^3的差才会是素数,所以可以得到
  15. i+1)^3-i^3;
  16. 代码:
  17. #include <cstdio>
  18. #include <iostream>
  19. using namespace std;
  20. int main()
  21. {
  22. //freopen("in.txt","r",stdin);
  23. int T;
  24. cin>>T;
  25. while(T--)
  26. {
  27. long long n;
  28. cin>>n;
  29. for(long long i=1;i<100000000;i++){
  30. if((i+1)*(i+1)*(i+1)-i*i*i>n){
  31. cout<<"NO"<<endl;
  32. break;
  33. }
  34. if((i+1)*(i+1)*(i+1)-i*i*i==n){
  35. cout<<"YES"<<endl;
  36. break;
  37. }
  38. }
  39. }
  40. return 0;
  41. }

发表评论

表情:
评论列表 (有 0 条评论,254人围观)

还没有评论,来说两句吧...

相关阅读