Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given two prime numbers, P1 and P2 , your task is to reach from P1 to P2 by changing only one digit at a time

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions