数素数
来源:互联网 发布:手机淘宝怎么做推广 编辑:程序博客网 时间:2024/04/28 23:13
数素数
Time Limit:1s Memory Limit:1000k
Total Submit:23202 Accepted:3658
下载样例程序(PE)
下载样例程序(ELF)
Problem
素数是的只能被1和它本身整除的自然数。判断一个数是素数的方法是使用2到该数的平方根的素数除它,若有能整除的则该数不是素数。
Input
本题有多组数据,每组数据由两个正整数M,N组成。(0<M<N<1000000)
Output
输出一个整数,表示介于M,N之间(包括M,N)的素数的数量。
Sample Input
5 101 36 8
Sample Output
221
C的解答和结果
#include <stdio.h>
#include <math.h>
void GetPrimeList(int* Array, int* Count, int Value)
{
int i, j, mid, cnt;
if(Value == 2){
Array[0] = 2;
*Count = 1;
}else{
mid = sqrt(Value);
GetPrimeList(Array, Count, mid);
cnt = *Count;
for(i = mid + 1; i <= Value; i++){
for(j = 0; j < *Count; j++){
if(i % Array[j] == 0) break;
}
if(j == *Count) Array[cnt++] = i;
}
*Count = cnt;
}
}
int main()
{
int Array[80000], Count, M, N, T, i, j ;
GetPrimeList(Array, &Count, 1000000);
while(scanf("%d%d", &M, &N) > 0){
if(M > N){ T = M; M = N; N = T; }
i = 0;
while(i < Count && M > Array[i]) i++;
j = i;
while(j < Count && N >= Array[j]) j++;
printf("%d/n", j - i);
}
return 0;
}
Memory: 336k
Time: 313ms
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 数素数
- 素数,回文数,回文素数
- 1013数素数(素数)
- 素数,回文数,回文素数,可逆素数
- 数素数问题
- fjnu 1339 数素数
- 1339数素数
- 水仙花数/素数
- 玩数(素数)
- NAND和NOR flash详解
- Understanding Oracle OLAP Dimensions And Cubes
- Themida.Custom.Build.V1.3.5.5 + V1.5.0.0.CracKed
- 人在江湖之一定要会的八个英文单词
- 如何让MFC窗口启动时最大化
- 数素数
- 正则表达式CHM教程
- 有关于用tcc.exe命令编译程序
- 如何获取CComboBox选择的文本
- JS大总结
- 成功的定义
- 谈判攻略
- 弹出窗口给开发者带来的烦恼
- 有个字符串由N个符号组成……