All pastes #536056 Raw Edit

authorblues

public cpp v1 · immutable
·published 2007-06-04 08:10 UTC
rendered paste body
#include <iostream>#include <string>#include <cstdlib>#include <cmath>#include <time.h>using namespace std;void main(int argc, char *argv[]){	unsigned int tm = clock();	int len_pi = argc < 2 ? 100 : atoi(argv[1]);	int sz = len_pi * 14 / 4;	int a, b, c, d, e, g, m;	char str[5];	string _str;	int *f = new int[sz + 1];	a = 10000;	b = 1;	c = sz;	e = 0;	while (b < c) f[b++] = a/5;	f[c] = 0;	m = 0;	while (c > 0)	{		g = c<<1;		d = 0;		b = c;		while (b > 0)		{			d += f[b]*a;			g--;			f[b] = d % g;			d /= g;			g--; b--;			if (b) d *= b;		}		c -= 14;		_itoa(e + d/a, str, 10);				_str = str;		while (_str.size() < 4) _str = "0" + _str;		cout << _str << ' ';		if (++m%10 == 0) cout << endl;		e = d % a;	}	cout << endl << "Generated " << len_pi << " digits of Pi in " << (clock() - tm) << "ms";}