Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
Câu 1:
uses crt;
var n,i,dem,j,kt1,kt2,a,b,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
if n mod 2=1 then
begin
a:=2;
b:=n-a;
kt:=0;
for i:=2 to trunc(sqrt(b)) do
if b mod i=0 then kt:=1;
if kt=0 then inc(dem);
end
else begin
for i:=2 to n div 2 do
begin
a:=i;
b:=n-i;
kt1:=0;
kt2:=0;
for j:=2 to trunc(sqrt(a)) do
if a mod j=0 then kt1:=1;
for j:=2 to trunc(sqrt(b)) do
if b mod j=0 then kt2:=1;
if (kt1=0) and (kt2=0) then inc(dem);
end;
end;
writeln('So cach phan tich ',n,' thanh tong hai so nguyen to la: ',dem);
readln;
end.
Câu 2:
uses crt;
var n,x:integer;
{-----------------ham-kiem-tra-nguyen-to-----------------}
function ktnt(x:integer):boolean;
var kt:boolean;
i:integer;
begin
kt:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then
begin
kt:=false;
break;
end;
if kt=true then ktnt:=true
else ktnt:=false;
end;
{---------------ham-kiem-tra-so-doi-xung---------------}
function ktdx(x:integer):boolean;
var kt:boolean;
d,i:integer;
st:string;
begin
str(x,st);
d:=length(st);
kt:=true;
for i:=1 to d do
if st[i]<>st[d-i+1] then
begin
kt:=false;
break;
end;
if kt=true then ktdx:=true
else ktdx:=false;
end;
{--------------chuong-trinh-chinh---------------}
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
if (ktnt(n)=true) and (ktdx(n)=true) then writeln(n,' la so nguyen to doi xung')
else writeln(n,' khong la so nguyen to doi xung');
x:=n+1;
repeat
x:=x+1;
until (ktnt(x)=true) and (ktdx(x)=true);
writeln('So nguyen to doi xung nho nhat lon hon ',n,' la: ',x);
readln;
end.
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long n,i;
bool kt;
int main()
{
cin>>n;
if (n>1)
{
kt=true;
for (i=2; i*i<=n; i++)
if (n%i==0) kt=false;
if (kt==true) cout<<n<<" la so nguyen to";
else cout<<n<<" khong la so nguyen to";
}
else cout<<n<<" khong la so nguyen to";
return 0;
}
Mình sẽ tạm hiểu đề này là viết chương trình in ra các số nguyên tố lớn hơn hoặc bằng n nha
#include <bits/stdc++.h>
using namespace std;
int n,m,i;
//chuongtrinhcon
bool ktnt(int n)
{
if (n<2) return false;
for (int i=2; i*i<=n; i++)
if (n%i==0) return false;
return true;
}
int main()
{
cin>>n;
cout<<"Cac so nguyen to nho hon bang n thoa man yeu cau la"<<endl;
for (int i=2; i<=n; i++)
if (ktnt(i)) cout<<i<<" ";
}
uses crt;
var a,b,i,x,y,n,m:integer;
st1,st2,st3,st4:string;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
str(a,st1);
str(b,st2);
st3:='';
for i:=length(st1) downto 1 do
st3:=st3+st1[i];
st4:='';
for i:=length(st2) downto 1 do
st4:=st4+st2[i];
val(st3,x,y);
val(st4,n,m);
writeln('So doi xung cua ',a,' la: ',x);
writeln('So doi xung cua ',b,' la: ',n);
writeln('Tong hai so doi xung cua ',a,' va ',b,' la: ',x+n);
readln;
end.
uses crt;
var a,b:longint;
st:string;
nt:array[1..100]of int64;
t,i,j,dem,kt,kt1,d,dnt:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
dem:=0;
for t:=a to b do
begin
str(t,st);
kt:=0;
d:=length(st);
for i:=1 to d do
if st[i]<>st[d-i+1] then kt:=1;
if kt=0 then
begin
dem:=dem+1;
nt[dem]:=t;
end;
end;
dnt:=0;
for i:=1 to dem do
begin
kt1:=0;
for j:=2 to nt[i]-1 do
if nt[i] mod j=0 then kt1:=1;
if kt1=0 then dnt:=dnt+1;
end;
writeln('so luong cac so nguyen to doi xung thoa man lon hon hoac bang ',a,' va nho hon hoac bang ',b,' la: ',dnt);
readln;
end.
uses crt;
var a,b:longint;
st:string;
nt:array[1..100]of int64;
t,i,j,dem,kt,kt1,d,dnt:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
dem:=0;
for t:=a to b do
begin
str(t,st);
kt:=0;
d:=length(st);
for i:=1 to d do
if st[i]<>st[d-i+1] then kt:=1;
if kt=0 then
begin
dem:=dem+1;
nt[dem]:=t;
end;
end;
dnt:=0;
for i:=1 to dem do
begin
kt1:=0;
for j:=2 to nt[i]-1 do
if nt[i] mod j=0 then kt1:=1;
if kt1=0 then dnt:=dnt+1;
end;
writeln('so luong cac so nguyen to doi xung thoa man lon hon hoac bang ',a,' va nho hon hoac bang ',b,' la: ',dnt);
readln;
end.