Cod sursa(job #1565136)

Utilizator Lazar_LaurentiuLazar Laurentiu Lazar_Laurentiu Data 10 ianuarie 2016 14:01:25
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

int nrz(int a)
{
    int fc=5,nrze=0;
    while(a/fc){
        nrze+=a/fc;
        fc*=5;
    }
    return nrze;
}
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;
      else
      if(nrzer<fa)s=m+1;
      else d=m-1;
    }
    m=(s+d)/2;
    if(m%5!=0) m=m/5*5;
    if(test)g<<m;
    else g<<-1;
    }
    f.close ();
    g.close ();
    return 0;
}