Usaco 1.3.4 prime cryptarithm

Source: Internet
Author: User

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 ;}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.