Pagini recente » Cod sursa (job #860893) | Cod sursa (job #1446791) | Cod sursa (job #2188373) | Cod sursa (job #2989899) | Cod sursa (job #1023135)
#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;
}