Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure read2nums(var a, b: longint);
- begin
- read(a, b); //read 2 nums
- end;
- function findPower(a,b:longint):longint;
- var i,res:longint;
- begin
- res:=1; //assign to the result val 1
- for i:=1 to b do //repeat cycle b times
- res:=res*a; //result eq itselp multiplie wth a
- findPower:=res; //assign to the func val result var
- end;
- function CountNumDschs(ch: longint): longint;
- var
- kol: longint;
- begin
- kol:=0; //firstly kol variable eq 0
- while ch > 0 do //repeat cycle while inputted num more than 0
- begin
- kol := kol + 1; //add to the kol var 1
- ch := ch div 10; //cut the last discharge of inputted num
- end;
- CountNumDschs := kol; //assign the the function result value kol variable
- end;
- function findArmst(inp: longint): longint;
- var
- num, sum, copy: longint;
- begin
- sum:=0; //firsly sum eq 0
- copy := inp; //assign to the copied var inputted val
- while inp > 0 do //repeat cycle while inputted more than 0
- begin
- num := inp mod 10; //assign to the num variable last discharge of inputted variable
- sum := sum + findPower(num, CountNumDschs(copy)); //add to the sum value whole part of power num^(count of discharges)
- inp := inp div 10; //cut the last discharge
- end;
- findArmst := sum; //assign to the result value sum variable
- end;
- procedure WriteArmsNums(a, b: longint);
- var
- ch: longint;
- checker: boolean;
- begin
- checker:=false;
- for ch := a to b do //iterate nums from a to b
- begin
- if findArmst(ch) = ch then //if num is armstrong then
- begin
- write(ch, ' '); //write this num
- checker := true; //checker is true
- end;
- end;
- if not(checker) then //if checker isnt true then
- write('-1') //write -1
- end;
- var
- a, b: longint;
- begin
- read2nums(a, b); //read borders of the range
- WriteArmsNums(a, b); //write all Armstrong num in range from a to b
- end.
Add Comment
Please, Sign In to add comment