Cod sursa(job #1413316)

Utilizator mist.moonDenisa Gherghel mist.moon Data 1 aprilie 2015 19:59:55
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <stdio.h>

using namespace std;
int p;
const int MAXQ=100000000;

int aparitii (int n)
{
    int ap=0, putere=5;
    while(n>=putere) { ap=ap+n/putere; putere*=5; }
    return ap;
}
int main(int argc, char *argv[])
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%d", &p);

    if(p==0) { printf("%d \n", 1); return 0; }
    else
    {
         int l=2, q=MAXQ;
         while(l<=q)
         {
             int m=l+(q-l)/2;
             int ap=aparitii(m);
             if(ap==p) { printf("%d \n", m/5*5); return 0; }
             else
                if(ap>p) q=m-1;
                else l=m+1;
         }
         printf("%d \n", -1);
         return 0;
     }


}