Cod sursa(job #1521169)

Utilizator dcmionutIonut Deaconu dcmionut Data 9 noiembrie 2015 23:07:13
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int get (int x)
{
  int i;
  x -= x % 5;
  while (x) {
    int a = x; 
    while (a % 5 == 0) { a /= 5; i++; x -= 5; }
  }
  return i; 
}
int main ()
{ 
  int p, a, b, m, k;
  ifstream f("fact.in");
  ofstream g("fact.out");
  f >> p;
  a = 1; b = 5 * p;
  m = a + (b - a) / 2;
  while (a <= b) {
    k = get (m);
    if (k == p) g << k;
    if (k < p) a = m + 1;
    if (k > p) b = m;
    m = a + (b - a) / 2;
  }
  f.close ();
  g.close ();
  return 0;
}