Cod sursa(job #127245)

Utilizator claudiu725Bruda Claudiu-Marcel claudiu725 Data 23 ianuarie 2008 17:36:45
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream.h>
#include <iostream.h>
int main()
{
   ifstream fin("fact.in");
   ofstream fout("fact.out");
   long p,n2,c,b,b2=0,n=0,ct=1;
  // cin>>p;
   fin>>p;
   while (p>=1)
   {
    n2=1;c=1;b=1;
    while (n2<=p)
    {
     c=n2;
     b=b*5;
     n2=b+c;
    }
    n=n+b;
    if (b2==b)
    {
     ct=ct+1;
     if (ct==5) n=-1;
    }
    else ct=1;
    b2=b;
    p=p-c;
    cout<<c<<endl;
   }
   if (!n) n=1;
  // cout<<n;
   fout<<n;
   return 0;
}