Orange Number
Time limit1sMemory limit1024 MB
Given K between 1000 and 10000, output three distinct natural numbers N under 100000 digits, not divisible by 10, such that the digit sum of N and of N squared both equal K, or -1 if impossible.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Implementation, Brute force
- Solved
- No attempts yet
Problem
Do you know the story of the British mathematician Hardy and the Indian mathematician Ramanujan? Hardy told Ramanujan, "The taxi I rode here had the number , which seems like a number without any special feature." Ramanujan replied, "No, is the smallest number that can be expressed as a sum of two cubes in two different ways." It is expressed as .
Today, Ihwan, who participated in a Codeforces round, said, "My rating became , which seems like a number without any special feature." Then Daniel replied, "No, the sum of the digits of is , and its square is , whose digit sum is also , so they are equal." Finding this property fascinating, Ihwan named an orange number and asked Daniel whether, for an integer , there exists a natural number whose digit sum is and whose square's digit sum is also . Let's help Daniel find such numbers!
Input
The first line gives an integer .
Output
Let be the sum of all digits of a natural number . is defined in base 10.
Find three natural numbers satisfying , and output them one per line. If there are multiple such , you may output any three. However, must not be a multiple of 10.
If no such exists, you must output a single integer . If an satisfying the condition exists, it is guaranteed that at least three exist.
Constraints
- For each number , must hold. (That is, must have at most 100,000 digits)
- Each number must not be a multiple of 10.
- Each number must be distinct.