化简一下得到 n^2 *( n + p ) = m^3
假设 n^2 和 n+p 之间有公共素因子 p , 那么 n+p = k*p , 即 n=p*(k-1),带进去得到 p^3 * (k-1)^2 *k = m^3 , (k-1)^2*k 肯定是不能表示成某一个数的三次幂的,假设不成立
所以 n^2 和 n+p 之间没有公共素因子 p , 那么可以假设n=x^3 , n+p=y^3 , 相减得到 p = y^3 - x^3 = (y-x) *(y^2+y*x+x^2) , 哈哈, p是素数,所以 y-x=1 , p =(x+1)^3 - x^3 = 3*x^2+3*x+1 , 暴力一下x,判断是否是素数就ok了
推公式,然后第一次写素数打表~~
#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <cstdio>
#include <queue>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define mod 9901
#define ll long long
bool prime[1000010];
int main()
{
memset(prime,true,sizeof(prime));
prime[0]=prime[1]=false;
for(int i=2;i*i<=1000000;i++)
{
if(prime[i]==true)
for(int j=2*i;j<=1000000;j+=i)
prime[j]=false;
}
int n;
while(~scanf("%d",&n))
{
int ans=0;
for(int i=1;;i++)
{
int temp=3*i*i+3*i+1;
if(temp>n) break;
if(prime[temp]) ans++;
}
if(ans==0)
printf("No Special Prime!\n");
else printf("%d\n",ans);
}
return 0;
}