0
0
Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
B1:
#include <bits/stdc++.h>
using namespace std;
bool nt(int n) {
for (int i=2; i<=sqrt(n); i++) if (n%i==0) return false;
if (n>1) return true;
return false;
}
int main() {
long n,d=0;
cin >> n;
while (n!=0) {
if (nt(n%10)) d++;
n/=10;
}
cout << d;
}
B2:
#include <bits/stdc++.h>
using namespace std;
bool nt(int n) {
for (int i=2; i<=sqrt(n); i++) if (n%i==0) return false;
if (n>1) return true;
return false;
}
int main() {
long n,m=0;
cin >> n;
while (n!=0) {
m=m*10+n%10;
n/=10;
}
if (nt(m)) cout << "So dao nguoc cua N la so nguyen to";
else cout << "So dao nguoc cua N khong la so nguyen to";
}
B3:
#include <bits/stdc++.h>
using namespace std;
bool tong(int n) {
int s=0;
while (n!=0) {
s+=n%10;
n/=10;
}
if (s==8) return true;
return false;
}
int main() {
int a,b;
cin >> a >> b;
for (int i=a; i<=b; i++) if (tong(i)) cout << i << " ";
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bài 1:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll m, n, dem;
bool snt(ll x)
{
if (x == 2)
return true;
if (x < 2)
return false;
for (ll i = 2; i <= sqrt(x); i++)
{
if (x % i == 0)
{
return false;
}
}
return true;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
while (n!=0)
{
m=n%10;
if(snt(m))
{
dem++;
}
n/=10;
}
cout<<dem;
return 0;
}
Bài 2:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll m, n, dem;
bool snt(ll x)
{
if (x == 2)
return true;
if (x < 2)
return false;
for (ll i = 2; i <= sqrt(x); i++)
{
if (x % i == 0)
{
return false;
}
}
return true;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
while (n != 0)
{
m = m * 10 + n % 10;
n /= 10;
}
if (snt(m))
{
cout << "YES";
}
else
{
cout << "NO";
}
return 0;
}
Bài 3:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a, b, m, n, i;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
for (i = a; i <= b; i++)
{
n = i;
m = 0;
while (n != 0)
{
m = m + n % 10;
n /= 10;
if (m > 8)
{
break;
}
}
if (m == 8)
{
cout << 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