Cod sursa(job #1803645)

Utilizator caesar2001Stoica Alexandru caesar2001 Data 11 noiembrie 2016 17:29:37
Problema Factorial Scor 85
Compilator c Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <stdio.h>
#include <stdlib.h>
FILE *in,*out;
/*int nrcifrezero(int a)
{
    int nr = 0,t = -1;
    if(a == 0)
        return 0;
    while(a > 0)
    {
        nr = nr + a/5;
        a = a/5;
    }
    return nr;
}*/
/*int cauta(int p)
{
    int a = 0,b = 1000000000,x,y;
    if(p == 0)
        return 1;
    while(a <= b)
    {
        x = (a + b)/ 2;
        y = nrcifrezero(x);
        if(p > y)
            a = x;
        if(p < y)
            b = x;
        if(p == y)
            return x - x%5;
    }
    return -1;
}*/
int main()
{
    in = fopen("fact.in","r");
    out = fopen("fact.out","w");
    int p,a = 0,b = 1000000000,z,nr = 0,cx,y,x;
    fscanf(in,"%d",&p);
    if(p == 0)
        fprintf(out,"1");
    while(a <= b)
    {
        nr = 0;
        x = (a + b)/ 2;
        cx = x;
        while(cx > 0)
    {
        nr = nr + cx/5;
        cx = cx/5;
    }
        y = nr;
        if(p > y)
            a = x;
        if(p < y)
            b = x;
        if(p == y)
        {
            fprintf(out,"%d",x - x%5);
            return 0;
        }
    }
    fprintf(out,"-1");
    return 0;
    fclose(in);
    fclose(out);
}