
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.


#include <bits/stdc++.h>
using namespace std;
long long x;
//chuongtrinhcon
bool ktnt(long long n)
{
for (int i=2; i*i<=n; i++)
if (n%i==0) return(false);
return(true);
}
//chuongtrinhcon
bool ktso(long long n)
{
int a=n%10;
int b=n/10; b=b%10;
int c=n/100; c=c%10;
int d=n/1000; d=d%10;
if (a+b==c+d) return(true);
else return(false);
}
//chuongtrinhchinh
int main()
{
for (x=1000; x<=9999; x++)
if ((ktnt(x)==true) and (ktso(x)==true)) cout<<x<<" ";
return 0;
}

program bai_toan;
var
N, i, sum: integer;
begin
write('Nhap so N: ');
readln(N);
write('Cac uoc cua ', N, ' khong ke ', N, ' la: ');
for i := 1 to N - 1 do
if N mod i = 0 then
write(i, ' ');
writeln;
sum := 0;
for i := 1 to N - 1 do
begin
if N mod i = 0 then sum := sum + i;
end;
if sum = N then writeln(N, ' la so hoan hao')
else writeln(N, ' khong phai la so hoan hao');
writeln;
writeln('Tat ca so hoan hao trong pham vi 1 -> ', N, ' la:');
for i := 1 to N do
begin
sum := 0;
for j := 1 to i - 1 do
begin
if i mod j = 0 then sum := sum + j;
end;
if sum = i then writeln(i);
end;
readln;
end.

uses crt;
var i,j,kt:integer;
begin
clrscr;
for i:=100 to 1 do write(i:4);
writeln;
for i:=2 to 100 do
begin
kt:=0;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
readln;
end.

uses crt;
var n,i,d,dem,kt,t,kt1,t1,t2,t3,max,min,x,j:integer;
a,b:array[1..100]of integer;
st:string;
begin
clrscr;
write('Nhap n='); readln(n);
str(n,st);
d:=length(st);
for i:=1 to d do
val(st[i],a[i],x);
dem:=1;
b[1]:=a[1];
for i:=1 to d do
begin
kt:=0;
for j:=1 to dem do
if a[i]=b[j] then kt:=1;
if kt=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
end;
writeln('Cac chu so cua ',n,' la: ');
for i:=1 to dem do
write(b[i]:4);
writeln;
t:=0;
for i:=1 to d do
t:=t+a[i];
writeln('Tong cac chu so cua ',n,' la: ',t);
kt1:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt1:=1;
break;
end;
if (kt1=0) and (t>1) then writeln(t,' la so nguyen to')
else writeln(t,' khong la so nguyen to');
writeln('Cac chu so o vi tri le cua ',n,' la: ');
t1:=0;
for i:=1 to d do
if i mod 2=1 then
begin
write(a[i]:4);
t1:=t1+a[i];
end;
writeln;
writeln('Tong cac chu so o vi tri le la: ',t1);
if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')
else writeln(t1,' khong la so chinh phuong');
writeln('Cac chu so o vi tri chan cua ',n,' la: ');
t2:=0;
for i:=1 to d do
if i mod 2=0 then
begin
write(a[i]:4);
t2:=t2+a[i];
end;
writeln('Tong cac chu so o vi tri chan la: ',t2);
t3:=0;
for i:=1 to t2 do
if t2 mod i=0 then t3:=t3+i;
if (t3=t2) and (t2>0) then writeln(t2,' la so hoan hao')
else writeln(t2,' khong la so hoan hao');
max:=a[1];
min:=a[1];
for i:=1 to d do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('Chu so lon nhat cua ',n,' la: ',max);
writeln('Chu so nho nhat cua ',n,' la: ',min);
writeln('Tong cua chung la: ',max+min);
readln;
end.

program SoNguyenTo;
var
A: array[1..100] of integer;
n, i, j: integer;
snt: boolean;
begin
write('Nhap so phan tu: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu A[', i, ']: ');
readln(A[i]);
end;
writeln('Cac so nguyen to trong day:');
for i := 1 to n do
begin
snt := true;
if A[i] < 2 then
snt := false
else
for j := 2 to round(sqrt(A[i])) do
if A[i] mod j = 0 then
begin
snt := false;
break;
end;
if snt = true then
writeln(A[i]);
end;
end.
program SoNguyenTo;
var
A: array[1..100] of Integer;
i, n: Integer;
isPrime: Boolean;
function IsNumberPrime(num: Integer): Boolean;
var
j: Integer;
begin
IsNumberPrime := True;
if num <= 1 then IsNumberPrime := False
else
for j := 2 to Round(Sqrt(num)) do
if num mod j = 0 then
IsNumberPrime := False;
end;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
isPrime := IsNumberPrime(A[i]);
if isPrime then
write(A[i], ' ');
end;
end.

Bài 1:
uses crt;
var n,i,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
kt:=0;
for i:=2 to n-1 do
if n mod i=0 then kt:=1;
if (kt=0) and (n>1) then writeln(n,' la so nguyen to')
else writeln(n,' khong la so nguyen to');
readln;
end.
Bài 2:
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.

uses crt;
var i,n:longint;
function NT(a:longint):boolean;
var dem,j:longint;
begin
dem:=0;
for j:=1 to a do if(a mod j=0)then inc(dem);
NT:=dem=2;
end;
begin
clrscr;
write('nhap n:');readln(n);
for i:=1 to n do if(NT(i))then write(i,' ');
readln
end.

Program HOC24;
var i,d,j,n integer;
begin
readln(n);
for i:=2 to n do
begin
d:=0;
for j:=1 to i do
if i mod j =0 then d=d+1;
if d=2 then write(i,' ');
end;
readln
end.
uses crt;
var i,j,kt:integer;
begin
clrscr;
for i:=10 to 99 do
begin
kt:=0;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
readln;
end.