Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure ReadNum(var ch: longint);
- begin
- read(ch); //read num
- end;
- function findPwr(inp: longint): longint;
- var
- i, num: longint;
- begin
- num := 1; //num eq 1
- for i := 1 to inp do //repeat cycle inpuuted value times
- num := num * 2; //multiplie num on 2
- findPwr := num; //assign to the function value num value
- end;
- function findMaxPwr(inp: longint): longint;
- var
- i, n: longint;
- begin
- i := 1; //i eq 1
- n := 0; //n eq 0
- while i < inp do //repeat cycle while i is less then inputted value
- begin
- i := i * 2; //multiplie i on 2
- n += 1; //add to n 1
- end;
- findMaxPwr := n; //assign to the function result n value
- end;
- procedure WritePrevPow(inp: longint);
- var
- i: longint;
- checker: boolean;
- begin
- checker := true; //firstly checker value is 1
- for i := -findMaxPwr(inp) to -1 do //iterate all nums from -(power of inputted num) to -1
- begin
- if(i mod 2 = 0) then //rum cycle if i is even
- if(findPwr(-i) <= inp) then //run cycle if power of -i eq or less then inputted num
- begin
- write(' ', findPwr(-i)); //write space and power of -i
- checker := false; //assign to the checker val 0
- end;
- end;
- if checker then //if checker eq 1 then
- write('0'); //write '0'
- end;
- var
- inp: longint;
- begin
- readnum(inp); //read input num
- WritePrevPow(inp); //write Previous Powers of inputted num
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement