Cod sursa(job #1283197)

Utilizator metrix007Lungu Ioan Adrian metrix007 Data 5 decembrie 2014 11:58:58
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");
long long n,p;
void citire()
{
    in >> p;
}

int nrz(int m)
{
 int nr=0,div=5;
 while(m/div!=0){
  nr= nr+ m/div;
  div=div*5;
 }
 return nr;
}

int cautare(int p)
{
    long long st=1,dr=10000000000,zero,m,copie;
    m=st+(dr-st)/2;
    while(st<dr)
    {
        zero=nrz(m);
        if(zero==p)
        {
                return m;
        }
        else if(zero<p)
        {
            st=m-1;
            m=st+(dr-st)/2;
        }
        else{
            dr =m+1;
            m=st+(dr-st)/2;
            }

    }
    return -1;
}



int main()
{
    citire();
    out << cautare(p);
    return 0;
}


/*
void cautare(int x)
{
    int poz=1, pas=1<<21;
    while (pas>>=1)
    {
        if (poz+pas<=n && a[poz+pas]<=x) poz+=pas;
    }
    if (a[poz]==x) return poz;
    return -1;
    m=st+ (dr-st)/2;
}
*/