Cod sursa(job #2024891)

Utilizator teodor440Teodor Tonghioiu teodor440 Data 21 septembrie 2017 15:12:34
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>

using namespace std;

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


int n, m, v[100], p;

int countzero(int n){
    int d = 5;
    int rez = 0;
    while(d <= n)
    {
        rez += n/d;
        d *= 5;
    }
    return rez;
}

int dim(int st, int dr){
    if(st == dr)
    {
        if(countzero(st) == p)
            return st;
        else
            return -1;
    }
    int mij = (st+dr)/2;
    if(countzero(mij) < p)
        return dim(mij+1, dr);
    else
        return dim(st, mij);
}

int main()
{
    int i, j;
    f >> p;
    if(p == 0){
        g << 1;
        return 0;
    }
    g << dim(1, 100000);

    return 0;
}