Cho N, tìm số bé hơn N có độ bền lớn nhất (0 ≤ N ≤ 2.000.000.000)

Cho N, tìm số bé hơn N có độ bền lớn nhất (0 ≤ N ≤ 2.000.000.000)

Năm 1973, nhà Toán học Neil Sloan đưa ra khái niệm độ bền của một số nguyên không âm N như sau:

  • Nếu N có một chữ số thì độ bền của N bằng 0.
  • Nếu N có từ 2 chữ số trở lên thì độ bền của N bằng độ bền của số nguyên là tích các chữ số của N cộng 1.

Cho N, tìm số bé hơn N có độ bền lớn nhất (0 ≤ N ≤ 2.000.000.000).

Persist.inp

persist.out

Giải thích

100

77

Doben(77)=Doben(49)+1=Doben(36)+1+1=Doben(18)+1+1+1=

Doben(8)+1+1+1+1=0+1+1+1+1=4

Giải thuật:

- Để tìm độ bền một số cần một hàm tính tích các chữ số của n TICH(n).

- Cho d = 0. Lặp lại điều kiện n >9 việc: Tăng d lên 1 thay n = TICH(n).

Program Do_ben;

uses crt;

Var n,d,i,j,max:longint;

Function TICH(n:Longint):Longint;

Var tam:integer;

Begin

     if n=0 then tam:=0 else tam:=1;

     While n<> 0 do

     Begin

          Tam:=tam*(n mod 10);

          n:=n div 10;

     End;

     TICH:=Tam;

End;

Begin

     clrscr;


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

     Max:=0;

     For i:=1 to n do

     Begin

     d:=0;

     j:=i;

     gotoxy(1,2);

     Write('Dang duyet den so: ',i);

     While j>9 do

     Begin

          d:=d+1;

          j:=TICH(j);

     End;

     if d>=Max then

     Begin

          max:=d;

          gotoxy(1,3);

          Writeln('So co do ben lon nhat dang la ',i,' do ben la:',d);

     End;

     End;

     Gotoxy(1,4);

     Writeln('Da duyet xong');

     Readln

End.

 

Bạn thấy bài viết này như thế nào?: 
Average: 5.1 (15 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

 
Add A Dropdown Admin Menu to Your Drupal Site

Thêm Dropdown Menu trong admin cho Drupal Site

One of things we often do for our training clients is simplify the admin area for them. There is a module that allows users to manage their site via a clean, dropdown menu. It has proven so popular that companies such as Acquia provide it by default to all their customers:

Hướng dẫn custom entity reference: Drupal & Entity reference

Hướng dẫn custom entity reference: Drupal & Entity reference

There are some good examples out there on how to create a custom Entity reference Behaviour plugin, but not so much for Selection handlers.

Hướng dẫn cách tạo web mail theo tên miền - Google

Hướng dẫn cách tạo web mail theo tên miền - Google

Sau khi thiết kế web cho doanh nghiệp, bạn cần quan tâm đến việc tạo thương hiệu cho doanh nghiệp mình.

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

 

Diet con trung