Cod sursa(job #984233)

Utilizator sebinechitasebi nechita sebinechita Data 13 august 2013 20:57:00
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;
ifstream fin ("fact.in");
ofstream fout("fact.out");

#define MAX 100000000

long long int i,n;

int zero(int x)
{
    int l=0;
    for(i=5;i<=x;i*=5)
    {
        l+=x/i;
    }
    return l;
}

int main()
{
    fin>>n;
    if(n==0)
    {
        fout<<1;
        return 0;
    }
    long long int l=0;
    long long int r=MAX;
    long long int p;
    do
    {
        int mid=l+(r-l)/2;
        p=zero(mid);
        if(p==n && mid%5==0)
        {
                fout<<mid;
                return 0;
        }
        else if(p<n)
            l=mid+1;
        else
             r=mid-1;

    }while(l<=r);

    fout<<-1;

    return 0;
}