Squares
Time limit2sMemory limit512 MB
Given n up to 10^18, find the smallest possible largest base k(n) in a sum of distinct squares equal to n, and count the overgrown integers up to n.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Number theory
- Solved
- No attempts yet
Problem
We call a decomposition of a positive integer any way to write it as a sum of distinct squares of positive integers. For example, 30 has two decompositions: . The number 8 has none.
Let be the minimum, over all decompositions of , of the largest integer whose square appears in the decomposition. If has no decomposition, then . For example, , , , , and .
An integer is overgrown if there is an integer with . In the example above, 378 is overgrown.
For a given , find and the number of overgrown integers from 1 to , inclusive.
Input
The first and only line contains a single integer (). Tests worth 45% of the score satisfy . A subset worth 30% satisfies , and a smaller subset worth 20% satisfies .
Output
Print two integers separated by a single space: first , then the number of overgrown integers from 1 to . If , print a minus sign (-) instead of the first number.