2017青岛赛区亚洲区域赛网络赛 1011题题解
2017-09-17 18:23
281 查看
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
思路:若能找到一个整数n满足 p=3n²+3n+1 则为YES(好不容易找到的规律)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
#define LL long long
#define INF 0x7fffffff
#define MAX 200010
#define PI 3.1415926535897932
#define E 2.718281828459045
using namespace std;
int t;
LL p;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%lld",&p);
bool flag=false;
p=p-1;
if(p%3==0){
p=p/3;
LL n=(LL)sqrt(1.0*p);
if(n*n+n==p) flag=true;
}
if(flag)printf("YES\n");
else printf("NO\n");
}
return 0;
}
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
思路:若能找到一个整数n满足 p=3n²+3n+1 则为YES(好不容易找到的规律)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
#define LL long long
#define INF 0x7fffffff
#define MAX 200010
#define PI 3.1415926535897932
#define E 2.718281828459045
using namespace std;
int t;
LL p;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%lld",&p);
bool flag=false;
p=p-1;
if(p%3==0){
p=p/3;
LL n=(LL)sqrt(1.0*p);
if(n*n+n==p) flag=true;
}
if(flag)printf("YES\n");
else printf("NO\n");
}
return 0;
}
相关文章推荐
- 2017亚洲区域赛青岛赛区网络赛---1011题目(详细解答,AC)A Cubic number and A Cubic Number
- 2017青岛赛区亚洲区域赛网络赛 The Dominator of Strings
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 HDU 6206 1001 Apple(三角形外接圆圆心和半径)
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 HDU 6212 1007 Zuma (区间DP)
- [置顶] 2017 ACM/ICPC 亚洲区域赛 青岛赛区
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 待补
- HDU - 6216 A Cubic number and A Cubic Number (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1011)
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 HDU 6208 1003 The Dominator of Strings(AC自动机)
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛总结
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛(J.Minimum Distance in a Star Graph)
- G.Finding the Radius for an Inserted Circle 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- [置顶] 2017年第42届ACM-ICPC亚洲区域赛青岛赛区(现场赛)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 A. Banana(连通性水题)
- HDU5024 2014 ACM-ICPC亚洲区域赛广州赛区网络赛C题 Wang Xifeng's Little Plot
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-E-Half-consecutive Numbers
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛总结
- 【2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛】 J Our Journey of Dalian Ends 【拆点费用流】
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F.islands (强联通分量 + 缩点)
- [置顶] 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E. Maximum Flow