

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <iostream>
#include <unordered_map>
#include <vector>
#define array vector
using namespace std;
int n;
array<int> prime;
void eratosthenes_sieve() {
int n = 1000;
array<bool> is_prime;
is_prime.resize(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; ++i)
if (is_prime[i]) {
prime.push_back(i);
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
void solve(int n) {
unordered_map<int, int> mark;
for (int i = 1; i <= n; i++) {
int x = i;
for (auto p : prime) {
if (p > x) break;
while (x % p == 0) {
x /= p;
if (mark.count(p) != 0) mark[p]++;
else mark[p] = 1;
}
}
}
int c = 0;
for (auto p : prime) {
if (c == mark.size()) break;
if (mark.count(p) != 0) {
cout << mark[p] << " ";
c++;
} else cout << 0 << " ";
}
cout << "\n";
}
int main() {
freopen("analyse.inp", "r", stdin);
freopen("analyse.out", "w", stdout);
eratosthenes_sieve();
while (cin >> n) solve(n);
return 0;
}
$\color{#fb3}{nguyenducnhattt}$
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h>
bool nt(int n){
if(n<2) return false;
for(int i=2;i*i<=n;i++)
if(n%i==0) return false;
return true;
}
using namespace std;
int main()
{
int n,i=2,d,b[1000],z=1;
long long tich=1;
cin>>n;
for(int i=1;i<=n;i++)
tich=tich*i;
for(int i=2;i<=tich;i++){
d=0;
while(tich%i==0&&nt(i)==true){
tich=tich/i;
d++;
}
if(nt(i)){
b[z]=d;
z++;}
}
for(int i=1;i<=z-1;i++)
cout<<b[i]<<" ";
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin
41
10578
29
chương trình ko chạy đc bn à
132
3555
95
hình như lỗi ở nhập xuất file á
132
3555
95
chứ test mẫu mà thử nhập xuất = màn hình vẫn được mà
0
50
0
chương trình ko chạy đc
132
3555
95
lỗi ở đâu z