hdu 6216 A Cubic number and A Cubic Number【数学】

hdu 6216 A Cubic number and A Cubic Number

题意:判断一个素数是否是两个立方数之差,就是验差分。

题解:只有相邻两立方数之差才可能,,因为x^3-y^3=(x-y)(x^2+xy+y^2),看(x-y),就能很快想到不相邻的立方数之差是不可能是素数的:),,然后把y=x+1代入,得:p=3x^2+3x+1,所以可得判断条件为:①p-1必须能被3整除;②(p-1)/3必须能表示为两个相邻整数之积。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 typedef long long ll;
 8 int main(){
 9     ll p ,t, i, j;
10     scanf("%lld", &t);
11     while(t--) {
12         scanf("%lld", &p);
13         i = sqrt((p-1)/3);
14         if((p-1)%3==0 && i*(i+1)==(p-1)/3) puts("YES");
15         else puts("NO");
16     }
17     return 0;
18 }

0ms

时间: 2024-10-06 05:18:19

hdu 6216 A Cubic number and A Cubic Number【数学】的相关文章

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 mul

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

[Javascript] Use Number() to convert to Number if possilbe

Use map() and Number() to convert to number if possilbe or NaN. var str = ["1","1.23","3","4.0","five", undefined, .00]; var num = str.map( (s) => { return Number(s); }); console.log(num); //[1, 1.23, 3

136. Single Number &amp;&amp; 137. Single Number II &amp;&amp; 260. Single Number III

136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Subscribe to see which co

&#39;Invalid update: invalid number of sections. The number of sections contained in the table view aft

问题:(删除tableview中的section时) Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (5) must be equal to th

HDU 6216 A Cubic number and A Cubic Number【数学思维+枚举/二分】

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

hdu 6216 A Cubic number and A Cubic Number

题意:给定一个素数,判定它是不是两个立方数之差. 题解:对于a^3+b^3=(a-b)(a^2-a*b+b^2),而一个素数的因子只有1和其本身,在加上(a^2-a*b+b^2)一定是大于1的,所以只有(a-b)为1的时候,才可能为解.预处理一下,打个表就好了. ac代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace

HDU 6216 A Cubic number and A Cubic Number(数学/二分查找)

题意: 给定一个素数p(p <= 1e12),问是否存在一对立方差等于p. 分析: 根据平方差公式: 因为p是一个素数, 所以只能拆分成 1*p, 所以 a-b = 1. 然后代入a = b + 1. 求出 3a2 + 3a + 1 = p 化简得a(a+1) = (p-1)/3 令(p-1)/3 = T, 问题化为是否存在整数a使得a(a+1) == T, 那么令 t = (int)sqrt(T),只要判定一下t * (t+1) == T ? 即可 另一种做法是打一个a的表(a只要打到1e6)

HDU6216 A Cubic number and A Cubic Number 和 广工的加强版

题目传送门_杭电版 题目传送门_广工版 广工版的是杭电版的加强版. 题意:判断一个质数是否是两个整数的立方差 ---- 数学题 题解: 根据立方差公式:\(a^3 - b^3 = (a - b)(a^2 + ab + b^2)\) 且 p 为质数 所以 \((a - b)(a^2 + ab + b^2)\) 其中任意一括号为 1,另一括号则为 p. 经计算检验(这里就不写啦),得 \((a - b) = 1\),\((a^2 + ab + b^2) = p\) . 因为\((a - b) = 1