Cod sursa(job #2645077)

Utilizator laur0700Laurentiu Postole laur0700 Data 26 august 2020 21:09:55
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int zero(int a)
{
    int nr_zero = 0;

    for(int i = 5; i<=a; i=i*5)
    {
        nr_zero = nr_zero + a/i;
    }
    return nr_zero;
}

int main()
{
    int p,st=1,dr=1000000,mij,sol = -1;

    fin>>p;

    if(p!=0){
        while(st<=dr){
            mij = (dr-st)/2+st;
            if(zero(mij)==p){
                sol = mij;
                dr = mij - 1;
            }
            else{
                if(zero(mij) > p){
                    dr = mij - 1;
                }
                else{
                    if(zero(mij)<p){
                        st = mij+1;
                    }
                }
            }
        }
    }
    else{
        fout<<0;
        return 0;
    }

    fout<<sol;


    return 0;
}