Cod sursa(job #1795899)

Utilizator Costel_DraghiciDraghici Constantin Costel_Draghici Data 2 noiembrie 2016 22:20:38
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <stdio.h>

using namespace std;

long long sol;

int putere(int k)
{
    long long x=5,y=0;
    while(x<=k)
    {
        y=y+k/x;
        x=x*5;
    }
    return y;
}

void caut(int p)
{
    int z=1<<30;
    while(z!=0)
    {
        if(putere(sol+z)<p)
            sol=sol+z;

        z=z/2;
    }
    if(putere(sol+1)==p)
        printf("%lld",sol+1);
    else
        printf("-1");

}

int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int p;
    scanf("%d",&p);
    caut(p);
}