Cod sursa(job #1268683)

Utilizator eneandradaEne Oana-Andrada eneandrada Data 21 noiembrie 2014 12:03:33
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int P,nr;

int cifre(int n)
{
    int putere=5,s=0;
    while(putere<=n)
    {
        s=s+(n/putere);
        putere=putere*5;
    }
    return s;
}

int cautare(int st, int dr)
{
    if(st>dr)
        return -1;
    int m=(st+dr)/2;
    if(cifre(m)<P)
        return cautare(m+1,dr);
    if(cifre(m)>P)
        return cautare(st,m-1);
    int u;
    if(cifre(m)==P)
        {
        while(m%5!=0)
            m--;
        return m;
        }
}

int main()
{
    f>>P;
    if(P==0)
        g<<"1";
    else
    g<<cautare(1,2000000000);
}