Cod sursa(job #2078459)

Utilizator CryshanaGanea Carina Cryshana Data 29 noiembrie 2017 16:45:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

int nr_0 (int x)
{
    int a=5,p=0;
    while(a<=x)
    {
        p+=x/a;
        a*=5;
    }
    return p;
}


int main()
{
ifstream fin("fact.in") ;
ofstream fout("fact.out");
  int P,r=0,pas=1<<30;
  fin>>P;
  while(pas!=0)
  {
      if(nr_0(r+pas)<P)
        r+=pas;
      pas/=2;
  }
  if(nr_0(r+1)==P) fout<<r+1;
  else
  fout<<"-1";
    return 0;
}