Cod sursa(job #2212161)

Utilizator Teodor_ICT2Teodor Melega Teodor_ICT2 Data 13 iunie 2018 15:12:29
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <cstdio>
using namespace std;
int zero(int n) {
    int p=5,s=0;
    while(n/p!=0) {
        s+=n/p;
        p*=5;
    }
    return s;
}
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int n,st,dr,mij,elem=-1,z;
    scanf("%d",&n);
    if(n==0) {
        cout<<1;
        return 0;
    }
    st=0;
    dr=5*n;
    while(st<=dr) {
        mij=(st+dr)/2;
        z=zero(mij);
        if(z>n)
            dr=mij-1;
        else {
            if(z<n)
                st=mij+1;
            else {
                elem=mij;
                dr=mij-1;
            }
        }
    }
    cout<<elem;
 
 
    return 0;
}