Chinaunix首页 | 论坛 | 博客
  • 博客访问: 358099
  • 博文数量: 53
  • 博客积分: 139
  • 博客等级: 入伍新兵
  • 技术积分: 589
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-27 01:55
个人简介

学习linux,学习编程。

文章分类

全部博文(53)

文章存档

2019年(1)

2018年(4)

2016年(4)

2014年(11)

2013年(33)

分类: 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()


阅读(1166) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~