Cod sursa(job #2336809)

Utilizator Seb0730Matei Sebastian Seb0730 Data 5 februarie 2019 16:14:49
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int n, p, st=1, dr=1000000000, mij, x, v, a;



int main()
{

    in>>p;
    while(st<dr){
        mij=(st+dr)/2;
        x=mij;
        n=0;
        while(x){
            x/=5;
            n+=x;
        }
        if(n>=p){
            dr=mij;
        }else{
            st=mij+1;
        }
    }
    v=dr, a=0;
    while(v){
        v/=5;
        a+=v;
    }
    if(a==p){
        out<<dr;
    }else{
        out<<-1;
    }


}