← RoseCode

ROSECODE 009

Prime Cryptarithm

elasolova · Programming ·

The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits 2,3,5,7 is selected, the cryptarithm is called a PRIME CRYPTARITHM.

   * * *
 x  * *
----------
  * * * *
  * * * *
----------
* * * * *

Write a program that will find all solutions to the cryptarithm above for any subset of digits from the set 1,2,3,4,5,6,7,8,9.


Sample Run

ENTER A SET OF DIGITS: 23468

   2 2 2
x    2 2
-----------
   4 4 4 <3 more not shown>
   4 4 4
------------
 4 8 8 4

The number of unique solutions = 4

Test your program with the prime digits 2357.What is the number of unique solutions?


Source:1993 USACO Qualifying Round 1