用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()

相关推荐
徐小黑ACG13 小时前
nginx配置文件
linux·服务器·nginx
新时代牛马13 小时前
Linux VFS 完整篇:从path_openat、dentry/inode 到page cache 与挂载排障
linux·运维·服务器
java_logo13 小时前
Docker 部署 Rocky Linux:轻松搭建 RHEL 兼容企业级基础镜像平台
linux·docker·容器·rocky linux·基础镜像·轩辕镜像·rhel 兼容
拂拉氏13 小时前
【知识讲解】 Linux虚拟地址空间认识
linux·虚拟地址空间
新时代牛马15 小时前
Linux 驱动中断与定时完整篇:从 request_threaded_irq 到hrtimer 选型与排障
linux·运维·服务器
分支预测失败17 小时前
RISC-V 核间中断 IPI 实战:从 MSIP 寄存器到 IMSIC 消息投递
linux·后端
GeW18 小时前
RHCE考试避坑指南"90%考生容易忽略的细节
linux
键盘会跳舞19 小时前
【C++多线程】死锁诊断工具实战:从 Windows 到 Linux 的全链路排查
linux·c++·windows·死锁
拂拉氏20 小时前
【知识讲解】 Linux环境变量的认识与使用
linux·环境变量
zhangrelay20 小时前
答疑-是否软件源问题都必须更换为国内呢-
linux·笔记·学习·ubuntu·ros2