Cod sursa(job #2611062)

Utilizator Groza_Iulia_DianaGroza Iulia Diana Groza_Iulia_Diana Data 6 mai 2020 11:39:05
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 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 st=1, dr=500000000;
    while(st<dr)
    {
        int mij=(st+dr)/2;
        nr=0, c=mij;
        while(c)
        {
            c/=5;
            nr+=c;
        }
        if(nr>=p)
            dr=mij;
        else
            st=mij+1;

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