Cod sursa(job #319326)

Utilizator mentallysafenotPerian Bogdan mentallysafenot Data 31 mai 2009 15:17:38
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 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);
    if(p==0)
    {
       g << "1\n";
       g.close();
       return 0;        
    }
    long i=1;
    long aux;
    x=y=p;
    while(1)
    {
       if(x==0&&y<0||x<0&&y==0||x==0&&y==0)
          break;
       if(x<0&&y<0)
       {
          g << "-1\n"; 
          g.close();
          return 0;            
       }
       
       if((i+1 )%2==0||(i+1)%5==0)
        i++;
      else
      i+=2;
       aux=i;
      
       while(aux%10==0)
       {
           aux/=10;
           x--;
           y--;            
       }
       
       while(aux%5==0)
       {
              aux/=5;
              y--;   
       }     
       while(aux%2==0)
       {
              aux/=2;
              x--;   
       }     
    }
    g << i << "\n";
    g.close();    
    return 0;
}