Cod sursa(job #3162379)

Utilizator RaresStanStan Rares RaresStan Data 29 octombrie 2023 07:25:54
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include<cmath>

using namespace std;

long long int factori_5(long long int x) {
    int cnt = 0;
    while (x > 0) {
        if (x % 5 == 0) {
            x /= 5;
            cnt++;
        }
        if (x % 5 != 0)
            break;
    }
    return cnt;
}

int main() {
    ifstream cin("fact.in");
    ofstream cout("fact.out");
    int p;
    cin >> p;
    long long int r = 0;
    long long i = 5;
    while (1) {
        p -= factori_5(i);
        if (p == 0) {
            cout << i;
            break;
        }
        if (p < 0) {
            cout << -1;
            break;
        }
        i += 5;
    }
    return 0;
}