HDU2866 Special Prime

题目重现

Give you a prime number p , if you could find some natural number (0 is not inclusive) n and m , satisfy the following expression:

n3+p∗n2=m3

We call this p a “Special Prime”.
AekdyCoin want you to tell him the number of the “Special Prime” that no larger than L.
For example:
If L=20
13+7∗12=23
83+19∗82=123

That is to say the prime number 7, 19 are two “Special Primes”.

Input

The input consists of several test cases.
Every case has only one integer indicating L .(1≤L≤106)

Output

For each case, you should output a single line indicate the number of “Special Prime” that no larger than L . If you can’t find such “Special Prime”, just output “No Special Prime!”

Sample Input

7
777

Sample Output

1
10

题解

这是一道数论题。

对于质数p, 正整数 n,m ,求

∑2≤p≤L[n3+p∗n2=m3]

可以导出: n,n+p 一定都是完全立方数。

结论1: n⊥p (n, p 互质)
假设 n⊥̸p ,有 n=kp,k∈Z+
原式化为

k3p3+k2p3=m3(k3+k2)p3=m3

由引理1得m不是整数,与条件矛盾!假设不成立。
所以 n⊥p 。

因为 gcd(n,n+p)=gcd(p,n)=1
所以 n⊥n+p

所以 n2(n+p)=m3 中 n,n+p 都是完全立方数,并且互质。

设 n=a3,n+p=b3,(b>a)
作差得:

p=b3−a3=(b−a)(b2+a2+ab)

因为 p 是质数,所以 b−a=1 ,可以消去 b 得:
p=3a2+3a+1,(a∈Z+)

于是:

∑2≤p≤L[n3+p∗n2=m3]=∑a>0,2≤3a2+3a+1≤L[3a2+3a+1是质数]

引理

引理1: k∈Z+,k3+k2 不是完全立方数

假设 k3+k2=a3
显然有 a>k

k2=a3−k3=(a−k)(a2+ak+k2)=(a2−k2)a+(a−k)k2≥(a2−k2)a+k2>k2

矛盾!假设不成立,因此对于 k∈Z+,k3+k2 不是完全立方数。

参考代码