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.
uses crt;
var n,kt,snt,b,m:longint;
{-----------------------------}
procedure nhap(var a:longint);
begin
write('nhap n:'); readln(a);
end;
{-------------------------------------------}
function ktnt(var x:longint):integer;
var kt,i,kt1,j:integer;
begin
kt:=0;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then
begin
kt:=1;
break;
end;
if kt=0 then ktnt:=1
else ktnt:=0;
end;
{-----------------------------------------------------}
BEGIN
clrscr;
nhap(n);
for m:=10 to n do
{-----------------------------------------------}
begin
begin
b:=m;
repeat
kt:=ktnt(b);
if kt=0 then break
else b:=b div 10;
until b<10;
if (ktnt(b)=1) and (b>1) then write(m,' ')
end;
end;
{-------------------------------------------------}
readln;
END.
program KiemTraSoSieuNguyenTo;
uses crt;
function IsPrime(num: integer): boolean;
var
i: integer;
begin
if num < 2 then
IsPrime := false
else
begin
IsPrime := true;
for i := 2 to trunc(sqrt(num)) do
begin
if num mod i = 0 then
begin
IsPrime := false;
break;
end;
end;
end;
end;
function IsSuperPrime(num: integer): boolean;
var
i, temp: integer;
begin
IsSuperPrime := true;
while num > 0 do
begin
if not IsPrime(num) then
begin
IsSuperPrime := false;
break;
end;
temp := num mod 10;
num := num div 10;
end;
end;
var
n: integer;
inputFile, outputFile: text;
begin
assign(inputFile, 'SNT.INP');
assign(outputFile, 'SNT.OUT');
reset(inputFile);
rewrite(outputFile);
readln(inputFile, n);
if IsSuperPrime(n) then
writeln(outputFile, 1)
else
writeln(outputFile, 0);
close(inputFile);
close(outputFile);
end.
bạn viết tới phần mình chưa học á.bạn viết lại đơn giản hơn được không
program ct;
uses crt;
var dem,n,s,max,t:longint;
begin
writeln('nhap n:');readln(n);
while n>0 do begin
s:=n mod 10;
t:=t+s;
if max<s then max:=s;
dem:=dem+1;
n:=n div 10;
end;
writeln('tong la',t,',','co',' ',dem,' ','chu so',',','chu so lon nhat la:',max);
readln
end.
bạn xem lại nha mik làm đây nhưng k bt đk
uses crt;
var a,x:longint;
{------------------ham-kiem-tra-so-nguyen-to---------------}
function ktnt(x:longint):boolean;
var kt:boolean;
i:longint;
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;
{---------------chuong-trinh-chinh-------------------}
begin
clrscr;
repeat
write('Nhap a='); readln(a);
until a>10;
if ktnt(a)=true then
begin
x:=a;
repeat
a:=a div 10;
if ktnt(a)=true then a:=a div 10;
until a<10;
if (ktnt(a)=true) and (a>1) then writeln(x,' la so sieu nguyen to')
else writeln(x,' khong la so sieu nguyen to');
end
else writeln(a,' khong la so sieu nguyen to');
readln;
end.
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<<" ";
}
program bai_1;
uses crt;
var i,n,j,d,dem:word;
begin
clrscr;
repeat
write('nhap n:');readln(n);
if (n<=0)or(n>=10000)then writeln('so ban nhap khong hop le, ban hay nhap lai:');
until (n>0)and(n<10000);
writeln('cac uoc so la so tu nhien cua ',n,' la:');
for i:=1 to n do
if n mod i=0 then write(i,' ');
writeln;
dem:=0;
for i:=2 to n do
begin
d:=0;
for j:=2 to i div 2 do
if i mod j=0 then inc(d);
if (d=0)and(n mod i=0)then inc(dem);
end;
if dem>0 then writeln('cac uoc so la so nguyen to cua ',n,' la:');
begin
d:=0;
for j:=2 to i div 2 do
if i mod j=0 then inc(d);
if (d=0)and(n mod i=0)then write(i,' ');
end;
if dem=0 then write(0);
readln;
end.
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.
Program HOC24;
var n: byte;
dem: integer;
i,x,x1: longint;
function nt(b: longint): boolean;
var j: longint;
begin
nt:=true;
if (b=2) or (b=3) then exit;
nt:=false;
if (b=1) or (b mod 2=0) or (b mod 3=0) then exit;
j:=5;
while j<=trunc(sqrt(b)) do
begin
if (b mod j=0) or (b mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
function snt(a: longint): boolean;
var d,d1: byte;
begin
d:=0; d1:=0;
while a<>0 do
begin
if nt(a) then d:=d+1;
d1:=d1+1;
a:=a div 10;
end;
if d1=d then snt:=true else snt:=false;
end;
begin
write('Nhap so N: '); readln(n);
case n of
1: begin x:=1; x1:=9; end;
2: begin x:=10; x1:=99; end;
3: begin x:=100; x1:=999; end;
4: begin x:=1000; x1:=9999; end;
5: begin x:=10000; x1:=99999; end;
6: begin x:=100000; x1:=999999; end;
7: begin x:=1000000; x1:=9999999; end;
8: begin x:=10000000; x1:=99999999; end;
9: begin x:=100000000; x1:=999999999; end;
end;
dem:=0;
for i:=x to x1 do
if nt(i) then
if snt(i) then
begin
write(i,' ');
inc(dem);
end;
writeln;
write('Tat ca co ',dem,' so');
readln
end.
uses crt;
var n,i,kt,dem:integer;
x,y,m,b:int32;
st,st1,st2,st3:shortstring;
{-------------chuong-trinh-con-kiem-tra-so-nguyen-to-----------------------}
function ktnt(var x:longint):integer;
var kt,i,kt1,j:integer;
begin
kt:=0;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then begin
kt:=1;
break;
end;
if kt=0 then ktnt:=1
else ktnt:=0;
end;
{-------------------------------------------}
begin
clrscr;
write('Nhap n='); readln(n);
st1[1]:='1';
for i:=2 to n do
st1[i]:='0';
st:='';
for i:=1 to n do
st:=st+st1[i];
val(st,x);
for i:=1 to n do
st2[i]:='9';
st3:='';
for i:=1 to n do
st3:=st3+st2[i];
val(st3,y);
dem:=0;
for m:=x to y do
{-----------------------------------------------}
begin
begin
b:=m;
repeat
kt:=ktnt(b);
if kt=0 then break
else b:=b div 10;
until b<10;
if (ktnt(b)=1) and (b>1) then
begin
write(m,' ');
inc(dem);
end;
end;
end;
writeln;
writeln('Co ',dem,' so sieu nguyen to co ',n,' chu so');
{-------------------------------------------------}
readln;
end.