CrazyDiver

Cycles/automorph nums[J]

Dec 12th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.16 KB | None | 0 0
  1. procedure VvodChisel(var a, b: longint);
  2. begin
  3.   read(a, b); //read 2 nums
  4. end;
  5.  
  6. function CountNumdschs(inp: longint): longint;
  7. var
  8.   num: longint;
  9. begin
  10.   num:=0;
  11.   while inp > 0 do  //repeat cycle while inputted num not eq 0
  12.     begin
  13.       num := num + 1;  //add to the num variable 1
  14.       inp := inp div 10;  //cut the last discharge of inputted nums
  15.     end;
  16.   CountNumdschs := num;  //assign to the function result 'num' variable value
  17. end;
  18.  
  19. function RaiseInDecsPow(inp: longint): longint;  //
  20. var
  21.   pwr, i: longint;
  22. begin
  23.   pwr := 1;  //assign to the power variable
  24.   for i := 1 to CountNumdschs(inp) do  //repeat num of inputted discharges times
  25.     pwr := pwr * 10;  //multiple power variable on 10
  26.   RaiseInDecsPow := pwr;  //assign to the function result power variable
  27. end;
  28.  
  29. function FindLastNumSqr(inp: longint): longint;  //
  30. var
  31.   pwr, i: longint;
  32.   lastdsch: real;
  33. begin
  34.   pwr := inp * inp;  //assign to the power variable sqr if inputted value
  35.   for i := 1 to CountNumdschs(inp) do  //repeat num of inputted discharges times
  36.     begin
  37.       lastdsch := lastdsch / 10 + (pwr mod 10) / 10;  //assign to the last discharge variable result of dividsion it on 10 plus last discharge of power value divided on 10
  38.       pwr := pwr div 10;  //cut the last discharge of power variable
  39.     end;
  40.   FindLastNumSqr := trunc(lastdsch * RaiseInDecsPow(inp));  //assign to the function result whole part of result of multiplication last discharge value and 10 in power of num of discharges
  41. end;
  42.  
  43. procedure wrtAutomorpthNums(a, b: longint);  //
  44. var
  45.   i: longint;
  46.   checker: boolean;
  47. begin
  48.   checker:=true;  //firstly checker is true
  49.   for i := a to b do  //iterate all nums from a to b
  50.   begin
  51.     if i = FindLastNumSqr(i) then  //if num is automorph then
  52.       begin
  53.         write(i, ' ');  //wrrite this num wth spaces
  54.         checker := false;  //assign to the chechcer false value
  55.       end;
  56.   end;
  57.   if checker then  //if checker value is true then
  58.     write('-1');  //write -1
  59. end;
  60.  
  61. var
  62.   a, b: longint;
  63.  
  64. begin
  65.   VvodChisel(a, b);  //read borders of the range
  66.   wrtAutomorpthNums(a, b);  //write all automorph nums in range from a to b
  67. end.
Add Comment
Please, Sign In to add comment