Viết chương trình thực hiện tách một số tự nhiên thành tổng của hai số nguyên tố

Viết chương trình thực hiện tách một số tự nhiên thành tổng của hai số nguyên tố

CHUYÊN ĐỀ CHIA HẾT – SỐ NGUYÊN TỐ

Mọi số tự nhiên đều có thể viết được dưới dạng tổng của hai số nguyên tố. Viết chương trình thực hiện tách một số tự nhiên thành tổng của hai số nguyên tố.

Cài đặt:

Program Tong_nguyen_to;

Var i,n:integer;

Function NT(n:integer):Boolean;

Var ok: Boolean;

     i:integer;

Begin

    ok:=true;

    For i:=2 to n-1 do if (n mod i) = 0 then ok:=ok and false;

    if n>=2 then NT:=ok else NT:=false;

End;

Begin

    Write('Nhap so n: ');Readln(n);

    For i:=2 to n div 2 do if (NT(i) and NT(n-i)) then Writeln(n,' = ',i,' + ',n-i);

    Readln

End.

Nhận xét:

Hãy mở rộng bài toán theo hướng

- Xét xem trong đoạn [n1...n2] số nào cho phép tách thành tổng hai số nguyên tố nhiều trường hợp nhất.

- Tách một số thành tổng ba số nguyên tố.

Bạn thấy bài viết này như thế nào?: 
Average: 9 (71 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Disappointing iPhone: Android Device Set to Gain

Disappointing iPhone: Android Device Set to Gain

Asian smartphone makers have a chance to exploit a rare letdown from pacesetter Apple Inc. after the new iPhone 4S failed to wow fans and investors, leaving Android rivals better placed to grab market share.

Ngày 2 – Học Big Data, So sánh Volume, Velocity và Variety

Ngày 2 – Học Big Data, So sánh Volume, Velocity và Variety

Các tổ chức ngày càng phát triển, dữ liệu liên quan cũng phát triển và ngày càng phức tạp hơn. Hầu hết các tổ chức lớn đều có dữ liệu trong nhiều ứng dụng

A review of the Samsung GALAXY Tab 10.1

A review of the Samsung GALAXY Tab 10.1

The Samsung GALAXY Tab 10.1 is seen as Samsungs response to iPad 2 tablet. This sleek phone features a wide screen display that is both sharp and bright, yet fitted in a body that is super slim.

Công ty diệt chuột T&C

 

Diet con trung