Cod sursa(job #1762998)

Utilizator NiceDayCraciun Mihai NiceDay Data 24 septembrie 2016 11:36:26
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream f1("fact.in");
ofstream f2("fact.out");
int nr;

int cifre(int x){
    int k=0;
    int n5 = 5;
    while(n5<=x){
        k+=x/n5;
        n5*=5;
    }
    return k;
}

int binar(int x){
    int dr=400000015;
    int st = 1;
    int mij;
    int k;

     while(dr>=st)
    {
        mij=(dr+st)/2;
        if(cifre(mij)<x) st=mij+1;
        else{
            dr=mij-1;
            k=mij;}
    }
    if(cifre(k)==x) return k;
    else return -1;
}

int main()
{

    f1 >> nr;
    if(nr==0) f2 << 1;
    else f2 <<binar(nr);
    f1.close();
    f2.close();
    return 0;
}