Cod sursa(job #2611060)

Utilizator Groza_Iulia_DianaGroza Iulia Diana Groza_Iulia_Diana Data 6 mai 2020 11:32:47
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>

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

int p, nr, c;

int main()
{
    fin >> p;
    int sol=0, st=1, dr=2000000;
    bool ok=0;
    while(st<dr)
    {
        int mij=(st+dr)/2;
        nr=0, c=5;
        while(c<=mij)
        {
            nr+=mij/c;
            c*=5;
        }
        c/=5;
        if(nr>=p)
            dr=mij;
        else
            st=mij+1;

    }
    c=5, nr=0;
    while(c<=st)
    {
        nr+=st/c;
        c*=5;
    }
    if(nr==p)
        fout << st;
    else
        fout << -1;
    return 0;
}