Given 2 4-digit prime numbers. Find a path of prime numbers where only one digit is changed from the first given prime n
Posted: Mon May 09, 2022 6:24 am
Given 2 4-digit prime numbers. Find a path of prime numbers
where only one digit is changed from the first given prime
number to the 2nd given prime number. Write a program in
C++ to find how many change is needed to go through in the
process. The first digit must be nonzero. Here is a solution
of an example from 1033 to 8179, the cost is 6.
Input
One line with a positive number: the number of test cases (at
most 100). Then for each test case, one line with two numbers
separated by a blank. Both numbers are four-digit primes (without
leading zeros).
Output
One line for each case, either with a number stating the minimal
cost or containing the word "Impossible".
Sample Input Sample Output 3 6 1033 8179 7 1373 8017 0 1033 1033
where only one digit is changed from the first given prime
number to the 2nd given prime number. Write a program in
C++ to find how many change is needed to go through in the
process. The first digit must be nonzero. Here is a solution
of an example from 1033 to 8179, the cost is 6.
Input
One line with a positive number: the number of test cases (at
most 100). Then for each test case, one line with two numbers
separated by a blank. Both numbers are four-digit primes (without
leading zeros).
Output
One line for each case, either with a number stating the minimal
cost or containing the word "Impossible".
Sample Input Sample Output 3 6 1033 8179 7 1373 8017 0 1033 1033