Given an integer N, the task is to check if the Digit Cube limit of an integer arrives at a fixed point or in a limit cycle.
A Digit Cube Limit is a number which repeatedly arrives at a point if its value is computed as the sum of cubes of its digits, i.e. they have the following properties:
- Arrive at a fixed point if it is an Armstrong number.
- Arrive at a limit cycle if it is repeating in a cycle.
Input: N = 3
Output: Reached to fixed point 153
F(3) = 3 * 3 * 3 = 27
F(27) = 2*2*2 + 7*7*7 = 351
F(351) = 3*3*3 + 5*5*5 + 1*1*1 = 153
F(153) = 1*1*1 + 5*5*5 + 3*3*3 = 153
Since a fixed point(= 153) was obtained, which is an Armstrong number of order 3. Below is the illustration:
Input: N = 4
Output: Arrived at cycle
F(4) = 4 * 4 * 4 = 64
F(64) = 6 * 6 * 6 + 4 * 4 * 4 = 280
F(280) = 2 * 2 * 2 + 8 * 8 * 8 + 0 * 0 * 0 = 520
F(520) = 5 * 5 * 5 + 2 * 2 * 2 + 0*0*0 = 133
F(133) = 1*1*1 + 3*3*3 + 3*3*3 = 55
F(55) = 5*5*5 + 5*5*5 = 250
F(250) = 5*5*5 + 2*2*2 + 0*0*0 = 133
A cycle between
133 -> 55 -> 250 -> 133 is obtained.
Below is the illustration of the same:
Approach: Follow the steps below to solve the problem:
- Create a hashMap to store the sum of the cube of digits of the number while iteration.
- Iterate for the next values for the sum of cube of digits of a number and Check if the next sum of the cube of digits is already present in the hashMap or not.
- If the number is already in the hash-map then, check if the number is an Armstrong number or not. If found to be true, then the number reaches a fixed point.
- Otherwise, If the number is not Armstrong number then continue.
Below is the implementation of the above approach:
3 reaches to a fixed point: 153
Time Complexity: O(N)
Auxiliary Space: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Find a Fixed Point (Value equal to index) in a given array
- Count of N-digit numbers having digit XOR as single digit
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Check if frequency of each digit is less than the digit
- Find the minimum sum of distance to A and B from any integer point in a ring of size N
- Source to destination in 2-D path with fixed sized jumps
- Percentage increase in the volume of cuboid if length, breadth and height are increased by fixed percentages
- Check whether N can be a Perfect Cube after adding or subtracting K
- Check if number formed by joining two Numbers is Perfect Cube
- C Program to check whether a number is a Perfect Cube or not
- Minimum decrements to make integer A divisible by integer B
- Digital Root (repeated digital sum) of square of an integer using Digital root of the given integer
- Count of m digit integers that are divisible by an integer n
- Smallest integer with digit sum M and multiple of N
- Biggest integer which has maximum digit sum in range from 1 to n
- Smallest integer greater than n such that it consists of digit m exactly k times
- Maximize a number considering permutations with values smaller than limit
- Count 'd' digit positive integers with 0 as a digit
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.