Cod sursa(job #2285870)

Utilizator baciuandreiBaciu Andrei baciuandrei Data 19 noiembrie 2018 14:05:17
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#define input "fact.in"
#define output "fact.out"
using namespace std;
namespace file{
    ifstream f(input);
    ofstream g(output);
    void close(){
        f.close();
        g.close();
    }
}
int counter(int a);
int main(){
    int n;
    long long x, i=1<<30;
    file::f>>n;
    while(i){
        if(counter(x+i)<n)
            x+=i;
        i/=2;
    }
    if(counter(x+1)==n)
        file::g<<x+1<<'\n';
    else 
        file::g<<"-1";
    file::close();
    return 0;
}

int counter(int a){
    int rez=0;
    while(a>=5){
        rez+=a/5;
        a/=5;
    }
    return rez;
}