1. Trang chủ
  2. » Giáo Dục - Đào Tạo

CHUYÊN đề số học (1)

11 252 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 11
Dung lượng 57,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

4:SỐ CHÍNH PHƯƠNG 6:PALINDROM.. 7:SỐ AMSTRONG *CHƯƠNG TRÌNH ĐẦY ĐỦ NHẤT VỀ SỐ HỌC.. - CHƯƠNG TRÌNH: function ngtox:longint:boolean; var kq:boolean; i:integer; begin kq:=true; if x...

Trang 1

Các loại số

1:SỐ NGUYÊN TỐ

2:SỐ SIÊU NGUYÊN TỐ

3:SỐ PHẢN NGUYÊN TỐ.

4:SỐ CHÍNH PHƯƠNG

6:PALINDROM.

7:SỐ AMSTRONG

*CHƯƠNG TRÌNH ĐẦY ĐỦ NHẤT VỀ SỐ HỌC.

1:SỐ NGUYÊN TỐ

- DN: số nguyên tố là có các ước là 1 và chính nó.

- CHƯƠNG TRÌNH:

function ngto(x:longint):boolean;

var kq:boolean;

i:integer;

begin

kq:=true;

if x<2 then kq:=false;

for i:=2 to trunc(sqrt(x)) do

if x mod i=0 then

kq:=false;

ngto:=kq;

end;

2:SỐ SIÊU NGUYÊN TỐ

- DN: là số nguyên tố mà khi ta bỏ một chữ số bênh phải thì

nó vẫn là số nguyên tố;

- CHƯƠNG TRÌNH

Trang 2

function ngto(x:longint):boolean;

var kq:boolean;

i:integer;

begin

kq:=true;

if x<2 then kq:=false;

for i:=2 to trunc(sqrt(x)) do

if x mod i=0 then

kq:=false;

ngto:=kq;

end;

function sieungto(x:longint):boolean; var kq:boolean;

begin

if ngto(x)=true then

while x>9 do

begin

x:=x div 10;

if ngto(x)=true then kq:=true

else

kq:=false;

if kq=false then break;

end

else

kq:=false;

sieungto:=kq;

end;

3:SỐ PHẢN NGUYÊN TỐ.

Trang 3

- DN:là số không phải nguyên tố và khi ta bỏ các chữ số bên phải

thì nó vẫn không là số nguyên tố

- CHƯƠNG TRÌNH:

function ngto(x:longint):boolean;

var kq:boolean;

i:integer;

begin

kq:=true;

if x<2 then kq:=false;

for i:=2 to trunc(sqrt(x)) do

if x mod i=0 then

kq:=false;

ngto:=kq;

end;

function phanngto (X:longint):boolean;

var kq:boolean;

begin

if ngto(n)=false then

while x>9 do

begin

x:=x div 10;

if ngto(x)=true then

kq:=false

else

kq:=true;

if kq=false then

break;

end

else

kq:=false;

phanngto:=kq;

Trang 4

4:SỐ CHÍNH PHƯƠNG

- DN: là số mà bình phương của 1 số bằng chính nó

- CHƯƠNG TRÌNH:

function chinhphuong(x:longint):boolean;

var kq:boolean;

i:integer;

begin kq:=false;

for i:=1 to trunc(sqrt(x)) do

if sqr(i)=x then begin

kq:=true;

break;

end;

chinhphuong:=kq;

end;

5:SỐ HOÀN THIỆN( SỐ HOÀN CHỈNH).

- DN : là số mà có tổng các ước của nó bằng chính nó.

- CHƯƠNG TRÌNH :

function hoanthien(x:longint):boolean;

var kq:boolean;

i:integer;

tong:longint;

begin kq:=false;

tong:=0;

for i:=1 to x-1 do

if x mod i=0 then tong:=tong+i;

Trang 5

if tong=x then kq:=true;

hoanthien:=kq;

end;

6:PALINDROM.

- DN : là số mà khi đọc từ phải sang trái bằng với đọc từ trái sang phải

- CHƯƠNG TRÌNH :

function palindrom(x:longint):boolean;

var kq:boolean;

i,code:integer;

num:longint;

st,s:string;

begin kq:=false;

s:='';

str(x,st);

for i:=length(st) downto 1 do s:=s+st[i];

val(s,num,code);

if num=x then kq:=true;

palindrom:=kq;

end;

7:SỐ AMSTRONG.

- DN:là số mà tổng lũy thừa k của các chữ số bằng chính nó,

trong đó k là số chữ số cùa số đó

- CHƯƠNG TRÌNH

function demchuso(so:int64):int64;

var dem:integer;

begin

Trang 6

dem:=0;

while so<>0 do

begin

dem:=dem+1;

so:=so div 10;

end;

demchuso:=dem;

end;

function luythua(a,k:longint):longint; var kq:int64;

i:integer;

begin

kq:=1;

for i:=1 to k do

kq:=kq*a;

luythua:=kq;

end;

function amstrong(n:int64):boolean; var num,s:int64;

k:integer;

kq:boolean;

begin

num:=n;

kq:=false;

k:=demchuso(n);

s:=0;

while n<>0 do

begin

s:=s+luythua(n mod 10,k); n:=n div 10;

end;

Trang 7

if s=num then kq:=true;

amstrong:=kq;

end;

*CHƯƠNG TRÌNH ĐẦY ĐỦ NHẤT VỀ SỐ HỌC.

program sohoc;

uses crt;

var n:longint;

a:byte;

function ngto(x:longint):boolean;

var kq:boolean;

i:integer;

begin kq:=true;

if x<2 then kq:=false;

for i:=2 to trunc(sqrt(x)) do

if x mod i=0 then kq:=false;

ngto:=kq;

end;

function sieungto(x:longint):boolean;

var kq:boolean;

begin

if ngto(x)=true then while x>9 do begin x:=x div 10;

if ngto(x)=true then kq:=true

else kq:=false;

if kq=false then break;

end else

Trang 8

kq:=false;

sieungto:=kq;

end;

function chinhphuong(x:longint):boolean; var kq:boolean;

i:integer;

begin

kq:=false;

for i:=1 to trunc(sqrt(x)) do

if sqr(i)=x then

begin

kq:=true;

break;

end;

chinhphuong:=kq;

end;

function hoanthien(x:longint):boolean; var kq:boolean;

i:integer;

tong:longint;

begin

kq:=false;

tong:=0;

for i:=1 to x-1 do

if x mod i=0 then

tong:=tong+i;

if tong=x then

kq:=true;

hoanthien:=kq;

end;

function palindrom(x:longint):boolean; var kq:boolean;

i,code:integer;

num:longint;

st,s:string;

Trang 9

kq:=false;

s:='';

str(x,st);

for i:=length(st) downto 1 do

s:=s+st[i];

val(s,num,code);

if num=x then

kq:=true;

palindrom:=kq;

end;

function phanngto (X:longint):boolean; var kq:boolean;

begin

if ngto(n)=false then

while x>9 do

begin

x:=x div 10;

if ngto(x)=true then kq:=false

else

kq:=true;

if kq=false then

break;

end

else

kq:=false;

phanngto:=kq;

end;

function demchuso(so:int64):int64; var dem:integer;

begin

dem:=0;

while so<>0 do

begin

Trang 10

dem:=dem+1;

so:=so div 10;

end;

demchuso:=dem;

end;

function luythua(a,k:longint):longint; var kq:int64;

i:integer;

begin

kq:=1;

for i:=1 to k do

kq:=kq*a;

luythua:=kq;

end;

function amstrong(n:int64):boolean; var num,s:int64;

k:integer;

kq:boolean;

begin

num:=n;

kq:=false;

k:=demchuso(n);

s:=0;

while n<>0 do

begin

s:=s+luythua(n mod 10,k); n:=n div 10;

end;

if s=num then kq:=true;

amstrong:=kq;

end;

BEGIN

clrscr;

write('Nhap n= '); readln(n); writeln('1:KT so nguyen to');

Trang 11

writeln('2:KT so sieu nguyen to');

writeln('3:KT so chinh phuong');

writeln('4:KT so hoan thien');

writeln('5:KT so phan nguyen to ');

writeln('6:KT so amstrong');

writeln('7:KT so palindrom');

write('Nhap kieu so can kiem tra: '); readln(a); case a of

1:write(ngto(n));

2:write(sieungto(n));

3:write(chinhphuong(n));

4:write(hoanthien(n));

5:write(phanngto(n));

6:write(amstrong(n));

7:write(palindrom(n));

end;

readln;

END.

Ngày đăng: 29/11/2016, 21:49

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w