Cod sursa(job #1833715)

Utilizator sabinantonSabin Anton sabinanton Data 22 decembrie 2016 22:41:31
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    long long st=1,dr=1000000000,mid,ct,p,fi=-1;

    f>>p;
    while(st<=dr)
    {
        mid=(st+dr)/2;
        ct=0;
        for(int i=5;i<=mid;i=i*5)
            ct+=(mid/i);
        if(p==ct)
        {
            fi=mid;
            dr=mid-1;
        }
        else
        {
            if(ct<p)
            {
                st=mid+1;
            }
            else
                dr=mid-1;
        }
    }
    g<<fi;
    return 0;
}