Cod sursa(job #1486959)

Utilizator Calin19Valentin Calin Calin19 Data 15 septembrie 2015 19:51:36
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,p,i;
int fo(int n)
{   int r=0,p5=5;
    while(n>=p5)
    {   r=r+n/p5;
        p5=p5*5;
    }
    return r;
}
int main()
{   f>>p;
    int st=1,dr=500000000;
    while(st<=dr)
    {   int mij=(st+dr)/2;
        if(fo(mij)<p) st=mij+1;
            else dr=mij-1;
    }
    if(fo(st)==p) g<<st;
        else g<<"-1";
    g.close(); return 0;
}