Cod sursa(job #3152984)

Utilizator buntaruButnaru Petre buntaru Data 27 septembrie 2023 15:07:45
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int nrzero(int a){
    int cnt=0;
    for(int i=5 ; i<=a ; i+=5){
        int ci = i;
        while(ci % 5 == 0){
            cnt++;
            ci/=5;
        }
    }
    return cnt;
}

int n , val;

int main()
{
    fin>>n;
    if(n == 0){
        fout<<1;
    }
    else{
        int st=1 , dr=n;
        while(st<=dr){
            int m = (st + dr) / 2;
            if(nrzero(5*m) >= n){
                dr = m - 1;
            }
            else{
                st = m + 1;
            }
        }
        fout<<5*st;
    }
    return 0;
}