Cod sursa(job #1062345)

Utilizator seby5381Marinescu Sebastian seby5381 Data 21 decembrie 2013 08:41:34
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<cstdio>
#include<cmath>

int caut(int s, int d);
int nr5(int x);

using namespace std;
int n,y;
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%d",&n);
    y=caut(1,100000000);
    while(y%5!=0)
        y--;
    printf("%d",y);
    return 0;
}

int caut(int s, int d)
{
    int jum;
    jum=(s+d)/2;
    if(n<nr5(jum))
    {
        d=jum;
        caut(s,d);
    }
    else if(n>nr5(jum))
    {
        s=jum;
        caut(s,d);
    }
    else  return jum;
}

int nr5(int x)
{
    int nr,k;
    nr=5;
    k=0;
    while(nr<x)
    {
        k+=x/nr;
        nr*=5;
    }
    return k;
}