Cod sursa(job #1553398)

Utilizator antanaAntonia Boca antana Data 19 decembrie 2015 19:27:42
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <cstdio>
#define MAX 800000000
using namespace std;

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    int p, l1, l2, mij, k, k1, f, gasit;
    scanf("%d", &p);
    l1=1;
    l2=MAX;
    gasit=0;
    while(l1<=l2&&gasit==0)
    {
        k=0;
        mij=(l1+l2)/2;
        f=5;
        while(f<=mij)
        {
            k+=mij/f;
            f*=5;
        }
        if(k==p){
                gasit=mij;
        }
        if(k>p) l2=mij-1;
        else if(k<p) l1=mij+1;
    }
    if(gasit!=0)
        printf("%d", gasit-gasit%5);
    else printf("-1");
    return 0;
}