Cod sursa(job #1384808)

Utilizator apostolandreiApostol Andrei Laurentiu apostolandrei Data 11 martie 2015 14:14:35
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");

int zero (int n){
  int nr = 0;
  while (n >= 5){
    nr += n/5;
    n /= 5;
  }
  return nr;
}

int solve(int p){
  int i = 0;
  int pas = 1 << 15;
  while (pas != 0){
    if (zero(i + pas) <= p)
      i += pas;
    pas /= 2;
  }
  if (i == p) return i;
  return -1;
}

int main()
{
    int p;
    in >> p;
    out << zero (p);
    out << solve (p);
    return 0;
}