

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
int n,j=1;
int nto (int x)
{
if(x<2) return 0;
for(int k=2;k*k<=x;k++) if(x%k==0) return 0;
return 1;
}
int tongcs(int x)
{
int a=0;
while (x > 0);
{
a+=x%10;
x=x/10;
} return a;
}
int main()
{
cout<<"Nhap n ";cin>>n;
int a[n];
int b[n+1];
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
if(nto(a[i])==1&&nto(tongcs(a[i]))==1)
{
b[j]=a[i];
j+=1;
}
}
cout<<j-1<<endl;
for(int i=1;i<j;i++) cout<<b[i]<<" ";
}
-LittleShadow-
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h>
using namespace std;
int sum(int n) {
int s = 0;
while (n > 0) {
s = s + (n % 10);
n = n / 10;
}
return s;
}
int isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,a,count = 0;
vector<int> res;
cin >> n;
for (int i = n; i > 0; --i) {
cin >> a;
if (isPrime(a) and isPrime(sum(a))) {
res.push_back(a);
count++;
}
}
cout << count << endl;
for (int i = 0; i < count; i++) cout << res[i] << ' ';
return 0;
}
$\\$
`\bb\color{#3a34eb}{\text{@hoanganhnguyen09302}}`
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin