Cod sursa(job #2938987)

Utilizator ax_dogaruDogaru Alexandru ax_dogaru Data 12 noiembrie 2022 20:48:20
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int check(int x) {
    int t=5, cnt=0;
    while(t<=x) {
        cnt+=x/t;
        t=t*5;
    }
    return cnt;
}

int main()
{
    int p, n, cnt;
    bool ok=false;
    fin >> p;
    if(p==0) {
        fout << "1";
    } else {
        n=p*5;
        while(ok==false) {
            cnt=check(n);
            if(cnt>p) {
                cout << p << " " << cnt;
                n-=5;
            } else if(p>cnt){
                cout << p << " " << cnt;
                fout << "-1";
                break;
            } else {
                fout << n;
                break;
            }
        }
    }
    return 0;
}