Unified State Exam
InterviewTime limit2sMemory limit512 MB
Convert an integer x into base -2, printing the number of digits and the binary digits from least significant to most.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Implementation, Greedy
- Solved
- No attempts yet
Problem
Sonya is a high school senior, and this year she has to take the Unified State Exam in computer science. She decided to start preparing early and began solving problems from past years' exams.
Many tasks require converting a number from one numeral system to another. Sonya handles such tasks with ease, but recently she came across a problem in one of the exams that seemed quite interesting: the number , given in decimal, has to be converted to the ()-base numeral system.
Formally, the representation of a number in the ()-base numeral system is a sequence of numbers , each of which is 0 or 1, where or , and the following equality holds:
For example, 3 in the ()-base numeral system is represented by the sequence : indeed, .
The problem asks to convert only one number to the ()-base numeral system, but Sonya became curious about the solution to this problem in the general case.
After long deliberation, she turned to you for help. Help her convert the given number to the ()-base numeral system.
Input
The single line of the input file contains one integer , the number Sonya wants to represent in the ()-base numeral system ().
Output
In the first line of the output file, print the number ().
In the second line of the output file, print numbers separated by spaces, the digits of the number in the ()-base numeral system ().
If several answers exist, print any of them.