Cod sursa(job #2024880)

Utilizator teodor440Teodor Tonghioiu teodor440 Data 21 septembrie 2017 15:00:28
Problema Factorial Scor 15
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){
    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++;
    if(countzero(j) == p)g << j;
	else g << j+1;

    return 0;
}