Odpowiedź:
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
vector<int>arr;
vector<pair<int,int>>ans;
bool checkPrime(int a){
if(a<2){
return false;
}
for(int i=2;i*i<=a;i++){
if(a%i==0){
return false;
}
}
return true;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
arr.push_back(x);
}
for(int i=1;i<n;i++){
if(checkPrime(arr[i-1]) && checkPrime(arr[i])){
ans.push_back({i-1,i});
}
}
for(int i=0;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
return 0;
}
Wyjaśnienie:
Dla przykładowego zestawu danych:
12
2 4 5 6 8 12 14 16 17 19 23 26
WYNIK:
8 9
9 10