Cod sursa(job #40329)

Utilizator TylorDurdenMuresan Ionut TylorDurden Data 27 martie 2007 12:53:41
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <math.h>
using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");
int n, p, s;

main()
{
      int k=0, P=1, t;
      in>>p;
      
      while(s!=p)
      {
                 s=0;
                 n+=5;
                 
                 while( P*5<=n )
                 {
                        P*=5;
                        k++;
                 }
                 
                 t=P;
                 
                 for(int i=1;i<=k;i++)
                 {
                         s+=n/t;
                         t/=5;
                 }
                 
                 if(s>p)
                 {
                        out<<-1;
                        exit(0);
                 }
      }
      
      out<<n;
}