Cod sursa(job #3167133)

Utilizator MogoneaMIhneaMogonea Mihnea Mihai MogoneaMIhnea Data 10 noiembrie 2023 09:19:25
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int p, aux, nr, mid, st ,dr, m, aux1;
int main(){
    fin>>p;
    if(p!=0){
        st=1;
        dr=p;
        while(st<=dr){
            mid=(st+dr)/2;
            aux=mid/5;
            nr=0;
            while(aux>0){
                nr+=aux;
                aux/=5;
            }
            aux1=mid+nr;
            if(aux1==p){
                m=mid;
                break;
            }
            if(aux1>p)
                dr=mid-1;
            else
                st=mid+1;
        }
        if(m*5>0)
            fout<<m*5;
        else
            fout<<'-1';
    }else
        fout<<1;
}