这就
#include "iostream"
#include "stdio.h"
#define Mod 10000
using namespace std;
int ku[] = {1,10,100,1000,10000};
class BigNum {
private:
int data[10000];
bool flag;
int len;
public:
BigNum(){len = 1;flag = false;data[0] = 0;}
~BigNum(){}
BigNum(int x) {
if(x < 0) {x = - x;flag = true;}
else{flag = false;}
len = 0;
if(x == 0)data[len ++] = x;
while(x) {data[len++] = x % Mod;x /= Mod;}
}
BigNum(char x[]) {
int end,l,cnt;
if(x[0] == '-') {end = 1;flag = true;}
else {end = 0;flag = false;}
l = strlen(x);cnt = 3;len = -1;
for(l -- ; l >= end; l --)
if(cnt == 3) {cnt = 0;data[++len] = x[l] - '0';}
else {cnt ++;data[len] = data[len] + (x[l] - '0') * ku[cnt];}
len ++;
}
void Scanf(int x) {
if(x < 0) {x = - x;flag = true;}
else flag = false;
len = 0;
if(x == 0)data[len ++] = x;
while(x) {data[len++] = x % Mod;x /= Mod;}
}
void Scanf(char x[]) {
int end,l,cnt;
if(x[0] == '-') {end = 1;flag = true;}
else {end = 0;flag = false;}
l = strlen(x);cnt = 3;len = -1;
for(l -- ; l >= end; l --)
if(cnt == 3) {cnt = 0;data[++len] = x[l] - '0';}
else {cnt ++;data[len] = data[len] + (x[l] - '0') * ku[cnt];}
len ++;
}
void ChangeSymbol() {if(flag)flag = false;else flag = true;}
bool Zero(){return (len == 1 && data[0] == 0);}
friend bool operator == (BigNum & a, BigNum &b) {
if(a.len != b.len || a.flag != b.flag)return false;
for(int i = 0; i <a.len; i ++) if(a.data[i] != b.data[i])return false;
return true;
}
friend bool operator == (BigNum & a,int & b) {BigNum c(b);return a == c;}
friend bool operator > (BigNum & a,BigNum & b) {
if(!a.flag && b.flag)return true;
if(a.flag && !b.flag)return false;
if(!a.flag && !b.flag) {
if(a.len > b.len)return true;
if(a.len < b.len)return false;
for(int i = a.len - 1; i >= 0 ; i --)
if(a.data[i] > b.data[i])return true;
else if(a.data[i] < b.data[i])return false;
return false;
}
if(a.len > b.len)return false;
if(a.len < b.len)return true;
for(int i = a.len - 1; i >= 0 ; i --)
if(a.data[i] > b.data[i])return false;
else if(a.data[i] < b.data[i])return true;
return false;
}
friend bool operator < (BigNum & a,BigNum & b) {return !(a > b) && !(a == b);}
friend bool operator >= (BigNum & a,BigNum & b) {return (a > b) || (a == b);}
friend bool operator <= (BigNum & a,BigNum &b) {return (a < b) || (a == b);}
friend BigNum operator + (BigNum & a, BigNum &b) {
BigNum c;int i;
if(a.flag == b.flag) {
c.flag = a.flag;
for(i = 0 ; i < b.len && i < a.len; i ++) c.data[i] = a.data[i] + b.data[i];
for( ; i < a.len ; i ++) c.data[i] = a.data[i];
for( ; i < b.len ; i ++) c.data[i] = b.data[i];
for(c.len = i , i = 0; i < c.len - 1; i ++) {if(c.data[i] >= Mod) {c.data[i] -= Mod;c.data[i+1] += i;}}
if(c.data[i] >= Mod) {c.data[i] -= Mod;c.data[i + 1] = 1;c.len ++;}
} else {
BigNum buf;
if(a.flag) {a.ChangeSymbol();if(a > b) {c = a;c.flag = true;buf = b;}
else if(a < b){c = b;c.flag = false;buf = a;} else {a.ChangeSymbol();c.len = 1;
c.data[0] = 0;c.flag = false;return c;}a.ChangeSymbol();}
else {b.ChangeSymbol();if(a > b) {c = a;c.flag = false;buf = b;}
else if (a < b){c = b;c.flag = true;buf = a;} else {b.ChangeSymbol();c.len = 1;
c.data[0] = 0;c.flag = false;return c;}b.ChangeSymbol();}
for(i = 0;i < buf.len; i ++) {c.data[i] -= buf.data[i];if(c.data[i] < 0) {c.data[i] += Mod;c.data[i+1] --;}}
for(i = c.len - 1; i >= 0 ; i --) if(c.data[i])break;
c.len = i + 1;
}
return c;
}
friend BigNum operator + (BigNum & a, int & b) {BigNum c(b);return a + c;}
friend BigNum operator - (BigNum & a,BigNum & b) {b.ChangeSymbol();BigNum c = a + b;b.ChangeSymbol();return c;}
friend BigNum operator - (BigNum & a, int & b) {BigNum c(b);return a - c;}
friend BigNum operator * (BigNum & a,BigNum & b) {
BigNum c;
if(a.Zero() || b.Zero())return c;
if(a.flag == b.flag)c.flag = false;
else c.flag = true;
c.len = a.len + b.len;
memset(c.data,0,sizeof(int)*(c.len));
for(int i = 0; i < a.len; i ++)
for(int j = 0; j < b.len; j ++) {int k = i + j;c.data[k] += a.data[i] * b.data[j];c.data[k+1] += c.data[k] / Mod;c.data[k] %= Mod;}
if(c.data[c.len-1] == 0)c.len --;
return c;
}
friend BigNum operator * (BigNum & a, int & b) {BigNum c(b);return a * c;}
friend int operator % (BigNum & a, int & b) {long long buf = 0;for(int i = a.len - 1; i >= 0; i --) {buf = (buf * Mod + a.data[i])%b;}return buf;}
friend BigNum operator / (BigNum & a,int & b) {
long long buf = 0;int i;for(i = a.len - 1; i >= 0; i --) {buf = buf * Mod + a.data[i];if(buf >= b)break;}a.len = i + 1;a.data[i] = buf / b;buf %= b;
for(i -- ; i >= 0 ; i --) {buf = buf * Mod + a.data[i];a.data[i] = buf / b;buf = buf % b;}return a;
}
void Printf() {if(flag)printf("-");printf("%d",data[len-1]);for(int i = len - 2; i >= 0 ; i --)printf("%04d",data[i]);puts("");}
};
int main() {
BigNum num[101];
int n;
num[0].Scanf(1);
for(int n = 0;n < 1;n ++) {
int buf = 4 * n + 2;
num[n+1] = num[n] * buf;
buf = n + 2;
num[n+1] = num[n+1] / buf;
}
while(scanf("%d",&n) == 1) {
num[n].Printf();
}
return 0;
}
posted on 2009-05-06 18:37
shǎ崽 阅读(839)
评论(2) 编辑 收藏 引用