Pascal

Modified: Wednesday, 22-12-2021 07:00 AM

program tim_so_hp;
var n,i:longint;   
    vt,d:integer;
procedure sohp(x,y:integer);
var i,j:integer;
    hp:longint;
begin   
   hp:=0;
   i:=0;
   while i<x do        
   begin
      inc(i);         
      inc(hp);
      while hp mod i>0 do
         inc(hp);
      if i=x then
         for j:=2 to y do
         hp:=hp+i
      else
      begin
         for j:=2 to i do
         hp:=hp+i;    
      end; 
   end;
   write('so can tim la: ',hp);
end;
{chuong trinh chinh}
begin
   write('nhap n = '); readln(n);
   i:=0; 
   vt:=1;    
   d:=0;  
   while  i<n do
   begin
      inc(i);
      inc(d);
      if d>vt then
      begin
        inc(vt);  
        d:=1;
      end;
   end; 
   writeln('dong thu: [ ',vt,' ] vi tri thu: [ ',d,' ]');
   sohp(vt,d);
   readln;
end.