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+pn2=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+712=23
83+1982=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 .(1L106)

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 ,求

2pL[n3+pn2=m3]

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

结论1: np (n, p 互质)
假设 n̸p ,有 n=kp,kZ+
原式化为

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

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

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

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

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

p=b3a3=(ba)(b2+a2+ab)

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

于是:

2pL[n3+pn2=m3]=a>0,23a2+3a+1L[3a2+3a+1]

引理

引理1: kZ+,k3+k2 不是完全立方数

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

k2=a3k3=(ak)(a2+ak+k2)=(a2k2)a+(ak)k2(a2k2)a+k2>k2

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

参考代码