You’re given an array of NN elements. You need to find the MEXMEX of the prime divisors of the array, which is defined as the first prime number which doesn’t divide any of the elements in the array.
You’re given an array of NN elements. You need to find the MEXMEX of the prime divisors of the array, which is defined as …
Share
RUN WITH INPUT
#include <bits/stdc++.h> using namespace std; long minf(vector<long> arr){ long max=arr[0]; for(long i=0;i<arr.size();i++){ if(arr[i]<=max){ max=arr[i]; } } return max; } long sumf(vector<long> arr){ long sum=0; for(long i=0;i<arr.size();i++){ sum=sum+arr[i]; } return sum; } long maxf(vector<long> arr){ long max=arr[0]; for(long i=0;i<arr.size();i++){ if(arr[i]>=max){ max=arr[i]; } } return max; } int isPrime(int n) { if(n%2==0){ return 0; } for (int i = 3; i <= sqrt(n);){ if (n % i == 0) return 0; i=i+2; } return 1; } int main() { // your code goes here ios_base::sync_with_stdio(false); cin.tie(NULL); int t=0; cin>>t; for(;t>0;t--){ int n=0; cin>>n; vector<int> arr; for(int i=0;i<n;i++){ int temp=0; cin>>temp; arr.push_back(temp); } for(int i=2;i<999999999;i++){ int flag=0; //cout<<i<<endl; if(isPrime(i)==1){ for(int j=0;j<arr.size();j++){ if(arr[j]%i==0){ flag=1; break; } } if(flag==0){ cout<<i<<endl; break; } } } } return 0; }