怎样用C语言解决这个问题:输出1到1000000000的所有素数,并且对称,,运行时间不超过30秒,非常感谢!
来源:百度知道 编辑:UC知道 时间:2024/06/03 21:53:06
The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of 3 and 1,000,000,000.
Output
The list of palindromic primes in numerical order, one per line. Then print the run time (seconds) at the last line.
Sample Output :
3
5
7
11
101
131
151
181
191
313
353
373
383
...
...
30 seconds
Output
The list of palindromic primes in numerical order, one per line. Then print the run time (seconds) at the last line.
Sample Output :
3
5
7
11
101
131
151
181
191
313
353
373
383
...
...
30 seconds
for (int i=1 ;i<=1000000000;i++)
{
if (sushu(i))
{
printf("%d",i);
}
}
bool sushu(int k)
{
return false;
是素数
则 return true;
}
#include<stdio.h>
#include<stdlib.h>//两个必须的文件
#include<time.h>//两个必须的文件
#include<algorithm>
using namespace std;
const __int64 MAX=1000000000;
const int MAXP=600000000;
int sto[1000000],c=0;
__int64 pa(__int64 n)
{
int bit[100],i=0,j,len;
while(n)
{
bit[i++]=n%10;
n/=10;
}
len=2*(i-1)+1;
i=0;
for(j=len-1;j>=i;j--,i++)
bit[j]=bit[i];
j=len;
n=0;
for(i=j-1;i>=0;i--)
n=n*10+bit[i];
return n;
}
__int64 pb(__int64 n)
{
int bit[100],i=0,j,len;
while(n)
{
bit[i++]=n%10;
n/=10;
}
len=2*(i);
i=0;
for(j=len-1;j>=i;j--,i++)