Cod sursa(job #3139672)

Utilizator SSKMFSS KMF SSKMF Data 30 iunie 2023 18:23:54
Problema Factoriale Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream cin ("factoriale.in");
ofstream cout ("factoriale.out");

vector < pair <int , int> > factori = {{2 , 0} , {3 , 0} , {5 , 0} , {7 , 0} , {11 , 0} , {13 , 0} , {17 , 0} , {19 , 0} , {23 , 0} , {29 , 0} , {31 , 0} , {37 , 0} , {41 , 0} , {43 , 0} , {47 , 0} , {53 , 0} , {59 , 0} , {61 , 0} , {67 , 0} , {71 , 0} , {73 , 0} , {79 , 0} , {83 , 0} , {89 , 0} , {97 , 0}};

int main ()
{
    int lungime , exponent;
    cin >> lungime >> exponent;

    for (int indice_1 = 1 , numar ; indice_1 <= lungime ; indice_1++)
    {
        cin >> numar;

        for (unsigned int indice_2 = 0 ; indice_2 < factori.size() ; indice_2++)
            for (int putere = factori[indice_2].first ; putere <= numar ; putere *= factori[indice_2].first)
                factori[indice_2].second += numar / putere;
    }

    unsigned long long termen = 1;
    for (auto factor : factori)
    {
        while (factor.second % exponent) {
            termen *= factor.first;
            factor.second++;
        }
    }

    cout << termen;
    cout.close(); cin.close();
    return 0;
}