Cod sursa(job #1023130)

Utilizator jul123Iulia Duta jul123 Data 6 noiembrie 2013 15:05:59
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<iostream>
#include<fstream>
using namespace std;
int check( int x)
{
    int nr = 0;
    while(x)
        {
        nr += x / 5;
        x /= 5;
        }
    return nr;
}
long long power( int k)
{
    if( k == 1)
        return 10;
    if( k == 0)
        return 1;
    if( k % 2)
        return 10 * power( k - 1);
    else
    {
        long long x = power( k / 2);
        return x * x;
    }
}
int binary_search(int n, int x)
{
    long long i, pas=1<<19;
    for(i = 0; pas != 0; pas /= 2)
        if(i + pas < n && check( i + pas) < x)
            i += pas;
    return i + 1;
}
int main()
{
    ifstream f( "fact.in");
    ofstream g( "fact.out");
    long long k, j;
    f >> k;
    j = power( k - 1);
    g<< binary_search( j, k);
}