学习linux,学习编程。
分类: LINUX
2013-01-21 02:07:11
下面是求解大质数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()