ghost79

导航

<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

统计

留言簿(0)

随笔分类

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

用计算机来计算圆周率

  目前PC机上流行的最快的圆周率计算程序是PiFast。它除了计算圆周率,还可以计算e和sqrt(2)。PiFast可以利用磁盘缓存,突破物理内存的限制进行超高精度的计算,最高计算位数可达240亿位,并提供基于Fabrice Bellard公式的验算功能。
最高记录:12,884,901,372位
时间:2000年10月10日
记录创造者:Shigeru Kondo
所用程序:PiFast ver3.3
机器配置:Pentium III 1G, 1792M RAM,WindowsNT4.0,40GBx2(IDE,FastTrak66)
计算时间:1,884,375秒 (21.8天)
验算时间:29小时

·G++编译器中的运算程序微机WindowsXP中Dev-cpp中的运算程序(30000位)(C++)
#include <iostream>
#include 
<fstream>

#define N 30010

using namespace std;

void mult (int *a,int b,int *s)
{
    
for (int i=N,c=0;i>=0;i--)
    
{
        
int y=(*(a+i))*b+c;
        c
=y/10;
        
*(s+i)=y%10;
    }

}


void divi (int *a,int b,int *s)
{
    
for (int i=0,c=0;i<=N;i++)
    
{
        
int y=(*(a+i))+c*10;
        c
=y%b;
        
*(s+i)=y/b;
    }

}


void incr(int *a,int *b,int *s)
{
    
for (int i=N,c=0;i>=0;i--)
    
{
        
int y=(*(a+i))+(*(b+i))+c;
        c
=y/10;
        
*(s+i)=y%10;
    }

}


bool eqs(int *a,int *b)
{
    
int i=0;
    
while (((*(a+i))==(*(b+i)))&&(i<=N)) i++;
    
return i>N;
}


int main(int argc, char *argv[])
{
    
int lpi[N+1],lls[N+1],lsl[N+1],lp[N+1];
    
int *pi=lpi,*ls=lls,*sl=lsl,*p=lp;
    
for (int i=0;i<=N;i++)*(pi+i)=*(ls+i)=*(sl+i)=*(p+i)=0;
    memset(pi,
0,sizeof(pi));
    memset(ls,
0,sizeof(ls));
    memset(sl,
0,sizeof(sl));
    memset(p,
0,sizeof(p));
    
*pi=*ls=*sl=1;
    
for (int i=1;true;i++)
    
{
        mult(ls,i,sl);
        divi(sl,
2*i+1,ls);
        incr(pi,ls,p);
        
if (eqs(pi,p)) break;
        
int *t;
        t
=p;
        p
=pi;
        pi
=t;
        
if (i%50==0) cout << i << "   ";
    }

    cout 
<< endl;
    mult(p,
2,pi);
    ofstream fout(
"pi.txt");
    fout 
<< *pi << ".";
    
for (int i=1;i<=N;i++)
    
{
        fout 
<< *(pi+i);
        
if (i%10==0) fout << " ";
        
if (i%80==0) fout << endl;
    }

    
return 0;
}
注:①运行时会有数据弹出,那是无关紧要的,只为了加快了感觉速度;
   ②最后的txt文本里有30010位,其中最后10位可能是错的。

posted on 2009-04-09 13:11 C家家 阅读(102) 评论(0)  编辑 收藏

评论

标题  
姓名  
主页
内容   
请输入验证码:
*
  登录  使用高级评论  Top 订阅回复  取消订阅
[使用Ctrl+Enter键可以直接提交]