Cod sursa(job #2159107)

Utilizator albucristianAlbu Cristian-Gabriel albucristian Data 10 martie 2018 19:11:10
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <climits>
using namespace std;
int main()
{
    int s,d,n,p,c,mij;
    ifstream in("fact.in");
    ofstream out("fact.out");
    in>>n;
    s=1;
    d=INT_MAX-1;
    while(s<d)
    {
        mij=(s+d)/2;
        p=5;
        c=0;
        while(p<=mij)
        {
            c=c+mij/p;
            p*=5;
        }
        if(c==n)
        {
            break;
        }
        else
        {
            if(c<n)
            {
                s=mij+1;
            }
            else
            {
                d=mij-1;
            }
        }
    }
    out<<mij;
    return 0;
}