Cod sursa(job #3221672)

Utilizator InformaticianInDevenire1Munteanu Mihnea Gabriel InformaticianInDevenire1 Data 7 aprilie 2024 19:51:00
Problema Factorial Scor 60
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 nrfactori5(int p) {
	int pow5 = 5,nr5 = 0;
	while (pow5<=p) {
		nr5 += p/pow5;
	    pow5 *= 5;
	}
	return nr5;
}

int main()
{
    int p;
    fin >> p;
    if (p==0){
        fout << 1;
    }else{
        int L = 1,R = 100000000,M;
        while (L<R){
            M = (L+R)/2;
            if (nrfactori5(M)<p){
                L = M+1;
            }else{
                R = M;
            }
        }
        if (nrfactori5(L)==p) fout << L;
        else fout << -1;
    }
    return 0;
}