2017 ACM/ICPC Asia Regional Qingdao Online 1011 A Cubic number and A Cubic Number

A Cubic number and A Cubic Number

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

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

10
2
3
5
7
11
13
17
19
23
29

Sample Output

NO
NO
NO
YES
NO
NO
NO
YES
NO
NO

Source

输入输出测试

水题呀    考试的时候想那么久,其实就是一个公式,却没有看到给出的数是一个素数,否则就直接解方程达到一个公式求出来,考试的时候错了十几遍(哪来的勇气。。最好让队友暴力过了。。)

以后看题目一定要看清楚呀!!!

给出一个p,p是素数(2 <= p <=1e12),判断是否存在正整数a,b使得

a*a*a - b*b*b = p

如果存在输出YES,否则输出NO。

我们知道立方差公式:

a*a*a  - b*b*b = (a-b)(a*a+a*b+b*b)

我们知道a*a*a - b*b*b = prime(素数)

所以(a-b)(a*a+a*b+b*b)  = prime;

由因为prime 只能由1*prime得来。

所以prime = 1*prime

所以(a-b) = 1, (a*a+a*b+b*b) = prime ,  a,b必是两个相邻的整数。

设b = x,a = x+1

则  (x+1)^3-x^3 = 3*x*x + 3*x + 1 = prime

3*x*x + 3*x = prime-1

x*x + x = (prime-1)/3

x(x+1) = (prime-1)/3

令:(prime-1)/3 = T;

x  = int(sqrt(T))  //解出一个x

若x*(x+1) == T

则说明存在一个整数a,是的a^3 - (a-1)^3 等于当前所输入的素数。

这个a就是我们解出的x再加1.

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        double n,prime;
        scanf("%lf",&prime);
        prime = prime - 1;
        n = prime/3;
        int a=(int)(sqrt(n));
        int b=a+1;
        if((double)a*b==n)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}  
时间: 2024-10-18 09:28:47

2017 ACM/ICPC Asia Regional Qingdao Online 1011 A Cubic number and A Cubic Number的相关文章

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=6215 Description Beerus needs to sort an array of N integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destr

2017 ACM/ICPC Asia Regional Qingdao Online

The Dominator of Strings Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 6778    Accepted Submission(s): 713 Problem Description Here you have a set of strings. A dominator is a string of the se

HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997    Accepted Submission(s): 306 Problem Description The empire is under attack again. The general of empire is planning to defend his

2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 782    Accepted Submission(s): 406 Problem Description I will show you the most popular board game in the Shanghai Ingress Resis

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 723 Problem Description Kelukin is a businessman. Every day, he travels arou

2016 ACM/ICPC Asia Regional Qingdao Online

吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以随便丢 有几个小盆友也比较靠谱 还有几个小盆友一开始有点担心 后来都做的挺棒 写题的选择上很尴尬 会写的别人也会 要么队内都不会 结果大概是写了一些板子题 感觉到了比较艰难的阶段 有些题是要我学着去写的 不会写没有突破 1001 I Count Two Three AC by ctr 指数不会很大,

hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^b*5^c*7^d 求靠近n的X值. 解题思路: 打表+二分查找 [切记用 cin cout,都是泪...] AC Code: 1 #include<bits/stdc++.h> 2 using namespace std; 3 long long na[100002]; 4 5 int main

【2016 ACM/ICPC Asia Regional Qingdao Online】

[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然后每次二分找就可以了. /* TASK:I Count Two Three 2^a*3^b*5^c*7^d的最小的大于等于n的数是多少 LANG:C++ URL:http://acm.hdu.edu.cn/showproblem.php?pid=5878 */ #include <iostream>