Cod sursa(job #2828365)

Utilizator lolismekAlex Jerpelea lolismek Data 7 ianuarie 2022 09:58:23
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int N = 500000000;

int exponent(int n){   /// cate numere multiple puteri ale lui 5 se gasesc in n
    int p = 5, s = 0;
    while(p < n){
        s = s + (n / p);
        p = p * 5;
    }
    return s;
}



int main()
{
    int p, st, dr, mij, ok;
    fin >> p;
    st = 1;
    dr = N + 1;
    ok = 1;
    if(p == 0){
        fout << 1;
        ok = 0;
    }
    while(dr - st > 1 && ok){
        mij = (dr + st) / 2;
        if(exponent(mij) == p){
            fout << mij - (mij % 5);
            ok = 0;
        }else{
            if(exponent(mij) < p){
                st = mij + 1;
            }else{
                dr = mij - 1;
            }
        }
    }
    if(ok)
        fout << -1;
    return 0;
}