下面是一个乘法竖式,如果用我们给定的那几个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式。
* * *
x * *
-------
* * *
* * *
-------
* * * *
数字只能取代*,当然第一位不能为0。
写一个程序找出所有的牛式。
Line 1: 数字的个数。
Line 2: N个用空格分开的数字(每个数字都∈{1,2,3,4,5,6,7,8,9}) 。
共一行,一个数字。表示牛式的总数。下面是样例的那个牛式。
2 2 2
x 2 2
------
4 4 4
4 4 4
4 8 8 4
5 2 3 4 6 8
1
Prime Cryptarithm
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 * *
-------
* * *
* * *
-------
* * * *
Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed. 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}.
PROGRAM NAME: crypt1 INPUT FORMAT Line 1: N, the number of digits that will be used Line 2: N space separated digits with which to solve the cryptarithm
SAMPLE INPUT (file crypt1.in) 5 2 3 4 6 8
OUTPUT FORMAT A single line with the total number of unique solutions. Here is the solution for the sample input:
2 2 2
x 2 2
------
4 4 4
4 4 4
4 8 8 4
SAMPLE OUTPUT (file crypt1.out) 1