Cod sursa(job #1530926)

Utilizator mariakKapros Maria mariak Data 21 noiembrie 2015 13:03:26
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
#define maxV 100005
using namespace std;
int n, m, x;
int n0(int x)
{
    int sum = 0;
    while (x)
    {
        sum += (x / 5);
        x /= 5;
    }
    return sum;
}
int bs(int x)
{
   int i = 0, p = 1 << 29;
   while (p)
   {
       if (n0(i + p) < x)
          i += p;
       p /= 2;
   }
   return i;

}
void read()
{
    freopen("fact.in", "r", stdin);
    scanf("%d", &x);
}
void write()
{
    freopen("fact.out", "w", stdout);
    int p = bs(x) + 1;
    if (n0(p) == x)
    printf("%d", p);
    else
    printf("-1");
}
int main()
{
    read();
    write();
    return 0;
}