Cod sursa(job #1023135)

Utilizator miu_mik93FMI - Paduraru Miruna miu_mik93 Data 6 noiembrie 2013 15:13:11
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include<cstdio>
#include<cstring>
#include<fstream>
#include <queue>

using namespace std;

#define NMax 50001

int cautbin(int v[], int n, int x)
{
	int i, pos = 1<<19;
	for (i = 0; pos != 0; pos = pos / 2)
	{
		if (i + pos <= n && v[i + pos] < x)
			i += pos;
	}
	return i+1;
}

int p;
FILE *f;
FILE *g;
int nr;
int isnumber(int n)
{
    nr = 0;
    while (n / 5 != 0)
    {
        nr += n / 5;
        n = n / 5;
    }
    if ( nr == p )
        return 1;
    return 0;
}
int gasit;
void cauta( int li, int ls )
{
    int m = (li + ls) / 2;
    if ( isnumber(m) )
    {
        gasit = m;
        while (isnumber(gasit-1))
        {
            gasit--;
        }
        fprintf(g, "%d", gasit);
    }
    else
    {
        if (li < ls)
        {
            if (p < nr)
                cauta(li, m-1);
            else
                cauta(m+1, ls);
        }
        else
            fprintf(g, "%d", -1);
    }
}
int main()
{
    f = fopen("fact.in", "r");  g = fopen("fact.out", "w");
    fscanf(f, "%d", &p);
	if (p == 0)
	{
		fprintf(g, "%d", 1);
		fclose(f); fclose(g);
		return 0;
	}
    fclose(f);
    cauta(0, 10000000000);
    fclose(g);
    return 0;
}