Cod sursa(job #1452519)

Utilizator stefan_andrei7Stefan Barabulea stefan_andrei7 Data 21 iunie 2015 11:32:45
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,p;
int fs(int n)
{
    int rez=0,p5=5;
    while(n>=p5)
    {
        rez=rez+n/p5;
        p5=p5*5;
    }
    return rez;
}
int main()
{
    int i;
    f>>p;
    int st=1,dr=500000000;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(fs(mij)<p)
            st=mij+1;
        else
            dr=mij-1;
    }
    if(fs(st)==p)
        g<<st;
    else
        g<<"-1";
    return 0;
}