Exponential Towers
Time limit2sMemory limit128 MB
Given a power tower a^(b^c), count the towers of height at least 3 with bases above 1 that evaluate to the same value.
- Level
Hard8 of 10
- Topics
- Number theory, Combinatorics, Recursion
- Solved
- No attempts yet
Problem
The number 729 can be written as a power in several ways: , and . It can also be written as , but that does not count as a power.
We go one step further. Write exponentiation with ^, so a^b means . The number 256 can then be written as 2^2^3 or as 4^2^2. The caret is right associative, so 2^2^3 means .
A tower of powers of height is an expression of the form a1^a2^a3^...^ak with and integers .
You are given a tower of powers of height 3 that represents an integer . How many towers of powers of height at least 3 represent ?
Input
The input has several test cases, one per line. Each test case has the form a^b^c, where , and are integers with . The number of test cases is not given, so read until the end of the input.
Output
For each test case, let and print on its own line the number of ways can be represented as a tower of powers of height at least 3.
The number 9585 is chosen so that the answer is always less than .