[Mảng 1 Chiều Cơ Bản]. Bài 55. Thay đổi nguyên tố
View as PDF
Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Problem source:
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho mảng A[] gồm N phần tử bạn hãy thay đổi tất cả các phần tử trong mảng là số nguyên tố thành số 28 và in ra mảng sau khi thay đổi.
Đầu vào
Dòng 1 là N : số phần tử trong mảng
Dòng 2 là N số viết cách nhau 1 dấu cách
Giới hạn
1≤N≤10^3
0≤A[i] ≤10^6
Đầu ra
In ra mảng sau khi thay đổi
Ví dụ :
Input 01
5
10 20 7 7 11
Output 01
10 20 28 28 28
Comments
include <bits/stdc++.h>
using namespace std;
vector<bool> sieve(int n) { vector<bool> prime(n+1, true); prime[0] = prime[1] = false; for (int i = 2; i <= int(sqrt(n)); i++) { if (prime[i]) { for (int j = i*i; j <= n; j += i) { prime[j] = false; } } } return prime; }
int main() { iosbase::syncwith_stdio(false); cin.tie(NULL);
}
include <bits/stdc++.h>
using namespace std; using ll = long long; using ull = unsigned long long; bool int(int n){ for (int i = 2; i <= sqrt(n);i++){ if(n%i==0) return false; } return n>1; } int main() { ios::syncwithstdio(false); cin.tie(nullptr); int n; cin >> n; while(n--){ int x; cin >> x; if(int(x)) cout << 28 << " "; else cout << x << " "; } return 0; }