Cod sursa(job #1563709)

Utilizator Lazar_LaurentiuLazar Laurentiu Lazar_Laurentiu Data 6 ianuarie 2016 15:20:08
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>

using namespace std;

int nrz(int x)
{
    int a=5,rez=0;
    while(x/a)
    {
        rez+=x/a;
        a*=5;
    }
    return rez;
}
int n5,n,i,ii,fa,d,s,m,nrzer;
bool test;

int main()
{
    ifstream f ("fact.in");
    ofstream g ("fact.out");
    f>>fa;
    s=5;d=5*fa;
    if(fa==0)g<<1;
    else{
    while(d>=s&&not test){
      m=(s+d)/2;
      nrzer=nrz(m);
      if(nrzer==fa)test=true;
      if(nrzer>fa)d=m-1;
      else s=m+1;
    }
    m=(s+d)/2;
    if(m%5!=0) m=m/5*5;
    g<<m;
    }
    f.close ();
    g.close ();
    return 0;
}