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

相关推荐
且从容.2 小时前
Ubuntu安装flume
linux·ubuntu·flume
承渊政道3 小时前
Linux网络学习【Reactor反应堆模式】
linux·网络·学习·ubuntu·reactor
且从容.5 小时前
ubuntu安装flink
linux·ubuntu·flink
爱和冰阔落7 小时前
【Linux网络】TCP 服务器如何并发处理多个客户端?从 fork、僵尸进程到双重 fork
linux·运维·服务器·网络
程序员沉梦听雨7 小时前
WSL2的安装与使用
linux·wsl
微小的鱼7 小时前
Linux的渲染与显示系统链路
android·java·linux
lisanmengmeng8 小时前
alertmanger 标签 rules 打上分组标签
linux·运维·服务器
Android系统攻城狮8 小时前
Linux FFmpeg深度解析之av_write_frame调用流程与实战(三十三)
linux·运维·服务器·ffmpeg·音视频进阶·ffmpeg音视频
Linux-lucky20 小时前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu
禁默20 小时前
启元 Q1 二次开发实践:Ubuntu 部署与仿真验证,从 PrimeConsole 到 ROS 2 Humble + RViz
linux·运维·ubuntu