| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 348 人关注过本帖
标题:求助用c语言编程 我的难题
只看楼主 加入收藏
雾雨非流云
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-11-3
收藏
 问题点数:0 回复次数:3 
求助用c语言编程 我的难题

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 The final score


The final score Score = Style(10) + Correct(50) + Speed(T)
where T = 70 - RunTime(seconds)

搜索更多相关主题的帖子: c语言 难题 
2007-11-03 16:35
hago
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-11-3
收藏
得分:0 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int sushu(long x)//判断数是否是素数,若不为素数输出0,否则输出不为0的数
{
long a=1;
int c=1;
double k;k=sqrt(x);
while(c&&a<k+1)
{
a++;c=x%a;
}
return c;
}
int nixushu(long x)//求一个数的逆序数
{
int a;
long b=0;

while(x)
{
a=x%10;x=x/10;b=b*10+a;
}
return b;
}

int main()
{
long a;
double D=pow(10,8);
for(a=3;a<10*D;a+=2)
{
if(a<2*D||(a>3*D&&a<4*D)||(a>7*D&&a<=8*D)||a>=9*D)//数a开头为24568的不计入
{
if(nixushu(a)==a)
{
if(sushu(a))
{
printf("%ld\n",a);
}
}
}
}

printf("------END----________--------");
return 0;

}
这是答案 供你参考下

2007-11-03 16:49
xuhuidream35
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-11-3
收藏
得分:0 
不懂!
2007-11-03 21:36
qiuchengw
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-10-31
收藏
得分:0 
写两个函数,一个判断是不是回文数,一个判断是不是素数,这两个算法网上都有代码的
2007-11-03 21:40
快速回复:求助用c语言编程 我的难题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016278 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved