Cod sursa(job #2156714)

Utilizator radugnnGone Radu Mihnea radugnn Data 8 martie 2018 22:36:00
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int P,st,dr,pt,S,n;
int main()
{
   fin>>P;
   st=1;
   dr=INT_MAX-2;
   while(st<=dr){
    n=(st+dr)/2;
    S=0;
    pt=5;
    while(pt<=n){
            S+=n/pt;
            pt*=5;

    }
    if(S>=P)
        dr=n-1;
    else
        st=n+1;

   }
   pt=5;
   S=0;
     while(pt<=st){
            S+=st/pt;
            pt*=5;

    }
    if(P==1)
    fout<<5;
    else
    if(S==P)
   fout<<st;
   else
    fout<<-1;


    return 0;
}