#include <bits/stdc++.h>
using namespace std;
int n,a,mx = -1e6,b[10101];
bool check(int x) {
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0) return 0;
return 1;
}
main () {
cin >>n;
for (int i = 1; i <= n; i++)
{
cin >>b[i];
mx = max(mx,b[i]);
if (check(b[i])) b[i] = mx;
cout <<b[i] <<" ";
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <bits/stdc++.h>
using namespace std;
int n,a,mx = -1e6,b[10101];
bool check(int x) {
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0) return 0;
return 1;
}
main () {
cin >>n;
for (int i = 1; i <= n; i++)
{
cin >>b[i];
mx = max(mx,b[i]);
}
for (int i = 1; i <= n; i++)
if (check(b[i])) b[i] = mx;
for (int i = 1; i <= n; i++)
cout <<b[i] <<" ";
}