Cod sursa(job #2024874)

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

using namespace std;

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

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

int countzero(int nr){
    int ct = 0, i;
    for(i = 5; i <= nr; i*=5){
        ct += nr/i;
    }
    return ct;
}

int dim(int st, int dr){
    int mid = (st+dr)/2, ctz = countzero(mid);
    if(st == dr || ctz == p) return mid;
    else if(ctz > p) return dim(st, mid);
    else return dim(mid+1, dr);
}

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

    return 0;
}