Cod sursa(job #3157183)

Utilizator LilGoat_4109Calin Andrei Cristian LilGoat_4109 Data 14 octombrie 2023 16:16:46
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");
 
int zero(int x)
{
    int c=0;
    while(x){
        c+=x/5;
        x=x/5;
        }
    return c;
}
int main()
{
    int n;
    in>>n;
    int s=0,d=5*n+1,r=d;
    while(s<=d){
        int mij=(s+d)/2;
        if(zero(mij)>=n){
            r=mij;
            d=mij-1;
        }
        else
            s=mij+1;
    }
    if (zero(r)!=n)
        r=-1;
    else if(n==0)
        r=1;
    out<<r;
    return 0;
}