Cod sursa(job #319256)

Utilizator mentallysafenotPerian Bogdan mentallysafenot Data 30 mai 2009 22:52:40
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <iostream>

using namespace std;
fstream f,g;
long p;
long x,y;
long d,c;

int main()
{
    f.open("fact.in",fstream::in);
    f >> p;
    g.open("fact.out",fstream::out);
    long i=1;
    x=y=p;
    while(1)
    {
      long aux=i;
       if(x==0&&y<0||x<0&&y==0||x==0&&y==0)
          break;
       if(x<0&&y<0)
       {
          cout << i << "\n";
          cin.get();
          g << "-1\n"; 
          g.close();
          return 0;            
       }
       while(aux%10==0)
       {
           aux/=10;
           x--;
           y--;            
       }
       while(aux%2==0)
       {
              aux/=2;
              x--;   
       }        
       
       while(aux%5==0)
       {
              aux/=5;
              y--;   
       }       
       i++; 
    }
    g << (i-1) << "\n";
    g.close();    
    return 0;
}