Cod sursa(job #2077419)

Utilizator madalin98Gherghe Madalin madalin98 Data 28 noiembrie 2017 00:59:55
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream>
#include<cstdlib>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int dr=50000000;
int zero(int x)
{
    int nr=0,n=5,xx;
    while(n<=x){
        if(n%25==0){
                xx=n;
        while(xx%5==0){
            ++nr;
            xx/=5;
        }}
        else ++nr;
        n+=5;
    }
    return nr;
}
int main()
{
    int p,st,m;
    f>>p;
    st=1;
    m=rand()%dr+1;
    while(zero(m)!=p&&st<=dr)
    {
        m=(st+dr)/2;
        if(zero(m)>p)dr=m-1;
          else st=m+1;
    }
    while(zero(m)==zero(m-1))
        m--;
    g<<m;
    return 0;
}