| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请大家看看为什么总是wa啊!!#include<iostream.h>
#include<string.h>
#include<stdio.h>
class HugeInt{
public:
HugeInt();
HugeInt(const char *);
HugeInt operator+(HugeInt &);
HugeInt operator+(int);
HugeInt operator*(HugeInt &);
HugeInt operator-(int);
void print();
private:
__int64 integer[3500];
int pointPosition;
};
HugeInt::HugeInt(){
for(int i=0;i<3500;i++)
integer[i]=0;
}
HugeInt::HugeInt(const char *string){
int i;
for(i=0;i<3500;i++)
integer[i]=0;
integer[3499]=2;
}
//+
HugeInt HugeInt::operator +(HugeInt &op2){
HugeInt temp;
int carry=0;
for(int i=3499;i>=0;i--){
temp.integer[i]=integer[i]+op2.integer[i]+carry;
if(temp.integer[i]>100000000){
temp.integer[i]-=100000000;
carry=1;
}
else
carry=0;
}
return temp;
}
HugeInt HugeInt::operator -(int num){
HugeInt temp=*this;
int i=3499;
while(temp.integer[i]==0){
temp.integer[i]=99999999;
i--;
}
temp.integer[i]--;
return temp;
}
HugeInt HugeInt::operator +(int num){
HugeInt temp=*this;
int i=3499;
while(temp.integer[i]==99999999){
temp.integer[i]=0;
i--;
}
temp.integer[i]++;
return temp;
}
//*
HugeInt HugeInt::operator*(HugeInt &op2){
HugeInt sum;
int i,j,k,h;
__int64 carry=0;
for(k=0;integer[k]==0;k++);
for(h=0;op2.integer[h]==0;h++);
for(i=3499;i>=k;i--){
HugeInt temp;
for(j=3499;;j--){
temp.integer[i+j-3499]=op2.integer[j]*integer[i]+carry;
carry=temp.integer[i+j-3499]/100000000;
temp.integer[i+j-3499]%=100000000;
if(j<=h&&carry==0)
break;
}
sum=sum+temp;
}
return sum;
}
//<<
void HugeInt::print(){
int i,j;
for( i=0;integer[i]==0;i++);
for(j=i;j<3500;j++)
printf("%I64d",integer[j]);
cout<<endl;
}
void main(){
int n;
cin>>n;
char w[1]={""};
HugeInt q(w);
cout<<2<<endl;
for(int i=1;i<n;i++){
q=(q-1)*q+1;
q.print();
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator