Digit cube
Practice
3 (22 votes)
Basic programming
C++
Problem
74% Success 13170 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}\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMediumSortingTwo pointer
Points:30
3 votes
Tags:
Binary search treeCombinatoricsGraphsMedium
Points:30
5 votes
Tags:
AlgorithmsApprovedMathMediumOpen