用bc脚本求解大质数

日期:2013-01-21

下面是求解大质数bc脚本,程序是从网上查找的C语言程序,然后做的修改。

/*this is a bc scripts, it can find some prime numbers.

the numbers between n to n+m, they are maybe some big numbers.

You can change k and m, k can affect n.

This program more part is copied from web

You can save it as primes.bc,

then use this command in bash: bc primes.bc

2013-1-20

*/

k=3*10^12 +1 #set k value

m=1000 #set m value

n=6 +k-k%6 #n is 6 * i

s=sqrt(n+m)+ 6 #it is max value to be divided a numbers

define main()

{

end=n+m

for(index=n;index+5<=end;index+=6) #Just test 6*n+1,6*n+5

{

num=index+1

if(judge(num)==1)

num

num=index+5

if(judge(num)==1)

num

}

}

define judge(judge_num)

{

if((judge_num%5)==0)

return (0);

for(indexs=6;indexs+5<=s;indexs+=6) #Just test 6*n+1,6*n+5

{

if(judge_num%(indexs+1)==0)

return (0);

if(judge_num%(indexs+5)==0)

return (0);

}

return (1);

}

main()

相关推荐
想做小南娘,发现自己是女生喵15 分钟前
第二周学习文档 Linux C 文件操作
linux·c语言·学习
djjjx.22 分钟前
Linux进程篇(三):深度硬核!全面起底 Linux 进程状态变化与内核链表动态解绑
linux·运维·服务器
乔旭伟25 分钟前
Linux 服务器环境搭建实战笔记:最小化安装、Docker Compose 编排与上线检查全流程
linux·服务器·笔记
Chenyu_3109 小时前
DPDK、TC 和 XDP:Linux 高性能网络到底在优化什么
linux·服务器·网络·缓存
陈让然10 小时前
WSL 桥接设置静态IP(快速)
linux·网络·ubuntu
乔旭伟10 小时前
Linux 服务器备份实战:一致性快照、日志归档与恢复演练
linux·运维·服务器
乔旭伟11 小时前
Linux 服务器安全加固实战:SSH、防火墙、补丁与入侵排查
linux·服务器·安全
刘胡子大叔12 小时前
备份包只有 1.5K?
linux·服务器·网络
无足鸟ICT12 小时前
【RHCA+】RPM包验证和数字证书
linux·运维·服务器
erzong23112 小时前
Linux操作系统:线程概念与控制
linux·算法