Digit cube
Practice
3 (22 votes)
Basic programming
C++
Problem
74% Success 13195 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Let \(n\) be an integer. We define a function \(f(n)\) which returns the cube of sum of digits of \(n\).
You are given two integers \(n\) and \(k\). You have to find the value of the integer that is returned when the function is recursively applied \(k\) times on \(n\).
Formally, you have to find the value of \(f^k(n)\).
Input format
- The first line of each test case consists of an integer \(T\) denoting the number of test cases.
- Each of the next \(T\) lines consists of two space-separated integers \(n\) and \(k\).
Output format
The output should consist of \(T\) lines each containing a single integer corresponding to the required value \(f^k(n)\).
Constraints
\(1\le T \le 10^6\)
\(1\le n, k \le 10^{15}\)
Sample Input
2 3 1 3 2
Sample Output
27 729
Explanation
The Sum of digits of 3 is 3.
- So, \(f^1(3)=f(3)=3^3=27\)
The Sum of digits of 27 is 9.
- So, \(f^2(3)=f(f(3))=f(27)=9^3=729\)
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:30
20 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMedium
Points:30
54 votes
Tags:
ApprovedImplementationMediumOpen
Points:30
6 votes
Tags:
Ad-HocMediumStacks
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor