Path Through Graph
Problem Description: You are given two natural numbers. Imagine these natural numbers as node on a graph. On this graph, a number is connected to its largest factor other than itself.
you have to find the shortest path between them and print the number of edges on that path.
Example 1: Input: 2 4
output: 1 Explanation: 4<-->2
Example 2: Input: 18 19
output: 4 Explanation: 18<-->9<-->3<-->1<-->19
Example 3: Input: 9 9
output: 0
Constraints:
0<= N1, N2 <=10^9
Example1 : Input: 15689 28
output: 5
C++ solution:
Also, read other solutions for CodeVita : Unblocker
No comments:
Post a Comment
Please do not enter any spam link in the comment box