Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

RGB1134 - Анхны тоон нууцлалт

Дараах нууцлалт нь дараах хэлбэрт таарсан үржвэрийн тухай ба өгөгдсөн N ширхэг цифрээс утгаа авна. Тэдгээрийг * - оор тэмдэглэнэ. Хэрэв зөвхөн {2,3,5,7} цифрээс тогтох цифрүүдээр энэ нууцлалыг хийдэг бол түүнийг АНХНЫ ТООН НУУЦЛАЛТ гэдэг ажээ.

      * * *

   x   * *

    -------

     * * *        

   * * *          

   -------

   * * * *

Одны оронд нэг л цифр байна. Мэдээж одоор үүсэх тоонууд нь тэгээр эхэлж болохгүй.

Зөвхөн өгөгдсөн цифрүүдээр зохиож болох дээрх хэлбэрт таарсан бүх боломжит үржвэрийн тоог олох програм бич.

 

Оролт

Мөр 1: N, байх ба энэ нь өгөгдөх цифрүүдийн тоо юм.

Мөр 2: Өгөгдөх N ширхэг тоо байрлана.

Гаралт

Хэдэн янзын давхцахгүй хариу байгааг илэрхийлсэн ганц тоо байна. Доор өгөгдсөн жишээнд таарсан ганц хариуг үзүүлсэн болно.

      2 2 2

    x   2 2

     ------

      4 4 4

    4 4 4

  ---------

    4 8 8 4 

Жишээ

Оролт :

5

2 3 4 6 8

Гаралт :

1

Орчуулсан : Б.Батбаатар


Нэмсэн:Bataa
Огноо:2010-02-18
Хугацааны хязгаарлалт:1s
Эх кодын хэмжээний хязгаарлалт:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Програмчлалын хэлүүд:ADA95 ASM32 ASM64 BASH BF C CSHARP C++ 4.3.2 CPP CPP14 C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCALA SCM guile SCM qobi ST TCL TEXT WHITESPACE

hide comments
2025-04-12 08:38:24
This poorly named task has nothing to do with prime numbers or even, really, prime digits. Sorry ‘bout that.

A cryptarithm is usually presented as a pencil-and-paper task in which the solver is required to substitute a digit for each of the asterisks (or, often, letters) in the manual evaluation of an arithmetic term or expression so that the consistent application of the digits results in a proper expression. A classic example is this cryptarithm, shown with its unique solution:

SEND 9562 S->9 E->5 N->6 D->2
+ MORE + 1085 M->1 O->0 R->8
------- -------
MONEY 10657 Y->7
Copy
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 *. Since the asterisks are generic, any digit from the input set can be used for any of the asterisks; any digit may be duplicated as many times as desired.

Consider using the set {2,3,5,7} for the cryptarithm below:

* * *
x * *
-------
* * * <-- partial product 1 -- MUST BE 3 DIGITS LONG
* * * <-- partial product 2 -- MUST BE 3 DIGITS LONG
-------
* * * *
Copy
Digits can appear only in places marked by ‘*’. Of course, leading zeroes are not allowed.

The partial products must be three digits long, even though the general case (see below) might have four digit partial products.

Note About Cryptarithm’s Multiplication
In USA, children are taught to perform multidigit multiplication as described here. Consider multiplying a three digit number whose digits are ‘a’, ‘b’, and ‘c’ by a two digit number whose digits are ‘d’ and ‘e’:

Note that this diagram shows far more digits in its results than the required diagram above which has three digit partial products!

a b c <-- number 'abc'
x d e <-- number 'de'; the 'x' means 'multiply'
-----------
p1 * * * * <-- product of e * abc; first star might be 0 (absent)
p2 * * * * <-- product of d * abc; first star might be 0 (absent)
-----------
* * * * * <-- sum of p1 and p2 (e*abc + 10*d*abc) == de*abc
Copy
Note that the ‘partial products’ are as taught in USA schools. The first partial product is the product of the final digit of the second number and the top number. The second partial product is the product of the first digit of the second number and the top number.

Write a program that will find all solutions to the cryptarithm above for any subset of supplied non-zero single-digits. Note that the multiplicands, partial products, and answers must all conform to the cryptarithm’s framework.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.