Cod sursa(job #73064)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 16 iulie 2007 15:46:38
Problema Patrate2 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<fstream.h>
long x,a[10000],b[100000],c[100000],N,nr,nr1;
void egalite(){
long x=99999;
while (c[x]==0)
x--;
for (long i=x;i>=0;i--)
 b[i]=c[i];
}
void inmultire(long &nr){
for (long ww=0;ww<=nr+nr1;ww++)
  c[ww]=0;
x=0;
for (long i=0;i<nr1+1;i++){
  int t=0;
 for (long j=0;j<nr+100;j++){
     c[j+i]+=b[j]*a[i]+t;
     t=c[j+i]/10;
     c[j+i]=c[j+i]%10;}
 if (t>0)  {
    c[nr+i]=t;
    x++;} }
 nr+=x;
}
int main(){
ifstream fin("patrate2.in");
ofstream fout("patrate2.out");
fin>>N;
if (N==1)
fout<<2<<"\n";
else{
b[0]=2;
nr=1;
for (long i=0;i<N*N-1;i++){
int t=0;
for (long j=0;j<nr;j++){
    b[j]=2*b[j]+t;
    t=b[j]/10;
    b[j]=b[j]%10;}
if (t>0){
b[nr]=t;
nr++;}}

a[0]=2;
nr1=0;
for (long y=2;y<=N;y++){
long x=y;
nr1=0;
while (x>0){
a[nr1++]=x%10;
x/=10;}
inmultire(nr);
egalite();
}
long g=nr*2+1;
while (b[g]==0)
  g--;
 for (long p=g;p>=0;p--)
   fout<<b[p];
fout<<"\n";    }
fin.close();
fout.close();
return 0;
}