Cod sursa(job #3250551)

Utilizator BeemoRobert Beemo Data 21 octombrie 2024 20:45:20
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int numar5( int x ) {
    int k = 0;
    while( x > 0 ) {
        x /= 5;
        k += x ;
    }
    return k;
}
int numarmic( int p) {
    int low = 0 , high = p * 5;
    while( low < high ) {
        int mid = (low + high) / 2;
        if(numar5(mid) < p ) {
            low = mid + 1;
        }
        else high = mid ;
    }
    if (numar5(low) != p)
        return -1;
    return low;
}
int P;

int main(){
    fin >> P;
    if( P == 0 )
        fout << 1;
    else fout << numarmic(P);





    return 0;
}