ICPC 青岛赛区 网络赛 1011 :A Cubic number and A Cubic Number<数学>
来源:互联网 发布:救世主大教堂知乎 编辑:程序博客网 时间:2024/06/05 22:42
A Cubic number and A Cubic Number
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 958 Accepted Submission(s): 465
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 numberp (2≤p≤1012) .
For each test case, a line contains a prime number
Output
For each test case, output 'YES' if given p is a difference of two cubic numbers, or 'NO' if not.
Sample Input
102357111317192329
Sample Output
NONONOYESNONONOYESNONO
题目意思是:给你一个素数p,要你判断这个数是不是两个立方数的差值。
思路:
用到数学公式(a^3-b^3)=(a-b)*(a^2-ab+b^2);
然后,题目说的是给你一个素数,素数的基本性质就是,他只有两个因子,因此我们可以得出 a-b=1 ,a^2-ab-b^2=p;
那么我们只需要证明后一个方程式成立就好了,并且得到的解要是个整数。
后一个方程化简后得到:3*b^2+3b+1=p;
运用中学学的解一元二次方程的公式,得到 ((-3+_sqrt(12*p-3))/6)
因此,只需要判断 sqrt开出来的值是不是整数,并且减去3之后能否被6整除就好了!
#include <cstdio>#include <algorithm>#include <iostream>#include <list>#include <queue>#include <cstring>#include <set>#include <map>#include<cmath>using namespace std;int main(){ int t; scanf("%d",&t); while(t--){ long long p; scanf("%lld",&p); long long pp=(long long )sqrt(12*p-3); if(pp*pp!=12*p-3) { //cout<<pp<<endl; printf("NO\n"); } else { if((pp-3)%6!=0) printf("NO\n"); else printf("YES\n"); } }return 0;}
阅读全文
0 0
- ICPC 青岛赛区 网络赛 1011 :A Cubic number and A Cubic Number<数学>
- 2017 icpc 青岛赛区 1011.A Cubic number and A Cubic Number
- 2017青岛网络赛1011 A Cubic number and A Cubic Number
- 2017亚洲区域赛青岛赛区网络赛---1011题目(详细解答,AC)A Cubic number and A Cubic Number
- 2017年ACM青岛站网络赛--A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number---ACM青岛Regional
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- **A Cubic number and A Cubic Number**
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- 2017 ACM/ICPC Asia Regional Qingdao Online:1011 A Cubic number and A Cubic Number
- HDU-2017 ACM/ICPC Asia Regional Qingdao Online-1011-A Cubic number and A Cubic Number
- 1011 A Cubic number and A Cubic Number
- hdu 6216 A Cubic number and A Cubic Number (2017 ACM/ICPC Asia Regional Qingdao Online)
- 【2017 ACM/ICPC Asia Regional Qingdao Online 1011】hdu 6216 A Cubic number and A Cubic Number
- 万恶的2017 ACM/ICPC Asia Regional Qingdao Online 1011 A Cubic number and A Cubic Number
- popwindow+viewpager+fragment并且可以滑动的问题
- [Android]不同包引用R文件
- 砝码组合
- Python:入门到实现网络爬虫 Day1
- redis操作Template测试
- ICPC 青岛赛区 网络赛 1011 :A Cubic number and A Cubic Number<数学>
- Linux
- 读书笔记:valueOf
- linux之第一个shell脚本
- 正则表达式随笔
- 挑战题一(1)
- C++之 typedef
- 基于双数组Trie的词典查询算法
- 51NOD 1090 三个数和为0 【暴力 二分】