#include <iostream> using namespace std; int main() { long long numberOfPrimeNumbers, currentCheck = 1, valueLimit, maxValue = 0; short *primeNumbers; cin >> numberOfPrimeNumbers >> valueLimit; primeNumbers = new short[numberOfPrimeNumbers]; for (int i = 0; i < numberOfPrimeNumbers ; i++) { cin >> primeNumbers[i]; } for (int i = 0; i < numberOfPrimeNumbers; i++) { currentCheck = 1; while ((currentCheck * primeNumbers[i]) <= valueLimit) { currentCheck *= primeNumbers[i]; } if (currentCheck > maxValue && currentCheck <= valueLimit) { maxValue = currentCheck; } } cout << maxValue << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> using namespace std; int main() { long long numberOfPrimeNumbers, currentCheck = 1, valueLimit, maxValue = 0; short *primeNumbers; cin >> numberOfPrimeNumbers >> valueLimit; primeNumbers = new short[numberOfPrimeNumbers]; for (int i = 0; i < numberOfPrimeNumbers ; i++) { cin >> primeNumbers[i]; } for (int i = 0; i < numberOfPrimeNumbers; i++) { currentCheck = 1; while ((currentCheck * primeNumbers[i]) <= valueLimit) { currentCheck *= primeNumbers[i]; } if (currentCheck > maxValue && currentCheck <= valueLimit) { maxValue = currentCheck; } } cout << maxValue << endl; return 0; } |