#include <cstdlib> #include <iostream> #include <math.h> #include <vector> using namespace std; long long reduce(long long value, vector<int> *primes) { long long currentValue = value; for (int i=0; i<primes->size(); i++) { while (currentValue % ((*primes)[i]) == 0) { currentValue = currentValue / ((*primes)[i]); } } return currentValue; } int main(int argc, char** argv) { int k; long long N; int prime; vector<int> primes; cin >> k; cin >> N; for (int i=0; i<k; i++) { cin >> prime; primes.push_back(prime); } while (reduce(N--, &primes) > 1) { } cout << (N + 1) << 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <cstdlib> #include <iostream> #include <math.h> #include <vector> using namespace std; long long reduce(long long value, vector<int> *primes) { long long currentValue = value; for (int i=0; i<primes->size(); i++) { while (currentValue % ((*primes)[i]) == 0) { currentValue = currentValue / ((*primes)[i]); } } return currentValue; } int main(int argc, char** argv) { int k; long long N; int prime; vector<int> primes; cin >> k; cin >> N; for (int i=0; i<k; i++) { cin >> prime; primes.push_back(prime); } while (reduce(N--, &primes) > 1) { } cout << (N + 1) << endl; return 0; } |