Given two prime numbers, P1 and P2, your task is to reach from P1 to P2 by changing only one digit at a time and also the number you get after changing a digit must also be a prime. For example...


Given two prime numbers, P1 and P2, your task is to reach from P1 to P2 by changing only one digit at a<br>time and also the number you get after changing a digit must also be a prime. For example suppose that<br>P1 is 1033 and P2 is 8179 (both primes), we can reach from P1 to P2 in following way:-<br>1033-> 1733-> 3733-> 3739-> 3779-> 8779-> 8179.<br>The first digit must be non-zero that is you can not go from 4-digit to 3-digit numbers. Note that there<br>may be multiple way to get to destination but you have to find the way in minimum number of steps.<br>For example the minimum number of steps to get from P1 to P2 in following examples are as follows<br>1033 8179 ANWSER:- 6<br>1373 8017 ANWSER:- 7<br>1033 1033 ANWSER:- 0<br>Hint: Apply BFS<br>

Extracted text: Given two prime numbers, P1 and P2, your task is to reach from P1 to P2 by changing only one digit at a time and also the number you get after changing a digit must also be a prime. For example suppose that P1 is 1033 and P2 is 8179 (both primes), we can reach from P1 to P2 in following way:- 1033-> 1733-> 3733-> 3739-> 3779-> 8779-> 8179. The first digit must be non-zero that is you can not go from 4-digit to 3-digit numbers. Note that there may be multiple way to get to destination but you have to find the way in minimum number of steps. For example the minimum number of steps to get from P1 to P2 in following examples are as follows 1033 8179 ANWSER:- 6 1373 8017 ANWSER:- 7 1033 1033 ANWSER:- 0 Hint: Apply BFS

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here