Cod sursa(job #2468611)

Utilizator amalia.gemanGeman Aamalia amalia.geman Data 5 octombrie 2019 18:16:52
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int Zerouri(int n)
{
    int ct=0;

    while(n)
        {
         ct=ct+n/5;
         n/=5;
        }

    return ct;
}


int main()
{
    int p;
    int n=1000000000;
    int s,d,m,z;

    fin>>p;

    //cautam in [1,n]

    s=1; d=n;
    while(s<d)
    {
        m=(s+d)/2;
        z=Zerouri(m);

        if(z==p)
            break;
        if(z<p)
            s=m+1;
        else
            d=m-1;
    }

    m=m-m%5;
    if(Zerouri(m)!=p)
        fout<<-1;
    else
        fout<<m;

    return 0;
}


//15
//5 10 15 20 25 30 35 40 45 50 55 60 65
//1 1  1   1  2  1  1  1  1  2  1 1   1