Usaco 1.3.4 prime cryptarithm
Question: How many numbers can I use to replace the multiplication vertical formula? How many kinds of statistics are there for the establishment of the formula?
To solve this problem, we can deepen our understanding of the vertical multiplication method. At first, we made two mistakes and thought about them carefully.
Details + code:
/* ID: 15257142 LANG: C task: crypt1 */# include <stdio. h> int A [20], B [2000], C [2000], d [2000], n, big [2000], small [2000], Mark [20]; int judge (INT num) {int R; while (Num> 0) {r = num % 10; If (MARK [R] = 0) return 0; num = num/10;} return 1;} int main () {freopen ("crypt1.in", "r", stdin); freopen ("crypt1.out", "W ", stdout); int I, J, K, T, num, R, count; scanf ("% d", & N); for (I = 0; I <= 9; I ++) MARK [I] = 0; for (I = 0; I <= n-1; I ++) {scanf ("% d", & A [I ]); Mark [A [I] = 1;} t = 0; for (I = 0; I <= n-1; I ++) {for (j = 0; j <= n-1; j ++) {for (k = 0; k <= n-1; k ++) {num = A [I] * 100 + A [J] * 10 + A [k]; B [T] = num; t ++ ;}} r = 0; for (I = 0; I <= T-1; I ++) {for (j = 0; j <= n-1; j ++) {If (B [I] * A [J] <100 | B [I] * A [J]> 999) continue; if (Judge (B [I] * A [J]) = 1) {d [R] = B [I] * A [J]; big [R] = B [I]; small [R] = A [J]; r ++ ;}} COUNT = 0; for (I = 0; I <= R-1; I ++) {for (j = 0; j <= R-1; j ++) {If (BIG [I]! = Big [J]) // the required number must be multiplied by the same three-digit number. Continue; // the same three-digit number may be multiplied by different three-digit numbers and single-digit numbers. If (d [I] * 10 + d [J] <1000 | D [I] * 10 + d [J]> 9999) continue; if (Judge (d [I] * 10 + d [J]) = 1) Count ++ ;}} printf ("% d \ n", count ); fclose (stdin); fclose (stdout); Return 0 ;}