We are given two numbers A and B, we need to write a program to determine if A and B can be reached starting from (1, 1) following the given steps. Start from (1, 1) and at every step choose a random number K and multiply K to any one of the two numbers obtained in the previous step and K2 to the other number.
Input : A = 3, B = 9 Output : yes Explanation: Starting from A = 1 and B = 1. We choose k=3 and multiply 3 with the first number to get A=3 and multiply k2=9 to the second- number to get B=9. Input : A = 60, B = 450 Output : yes Explanation : Starting from A = 1 and B = 1, Step 1: multiply k=3 and k2 to get 3 and 9 Step 2: Multiply k=5 and k2 = 25 to get to 15 and 225 Step 3: Multiply k2=4 and k=2 to get to A=60 and B=450
The idea to solve this problem is to observe closely that at each step we are multiplying k and k2 to the numbers. So if A and B can be reached, it will have k^3 at every step as factors in A*B. In simple words, if the number A*B is a perfect cube and it divides A and B both, only then the number can be reached starting from 1 and 1 by performing given steps.
Below is the implementation of above idea:
- Minimum step to reach one
- Find the number of consecutive zero at the end after multiplying n numbers
- Minimum operations required to convert X to Y by multiplying X with the given co-primes
- Check if elements of array can be made equal by multiplying given prime numbers
- Program to print Step Pattern
- Steps to reduce N to zero by subtracting its most significant digit at every step
- Delete odd and even numbers at alternate step such that sum of remaining elements is minimized
- Maximize the sum of array by multiplying prefix of array with -1
- Count ways to reach the n'th stair
- Minimum number of jumps to reach end
- Reach the numbers by making jumps of two given lengths
- Minimum number of moves to reach N starting from (1, 1)
- Number of steps required to reach point (x,y) from (0,0) using zig-zag way
- Find the minimum number of steps to reach M from N
- Minimize the number of steps required to reach the end of the array | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.