两位数乘三位数等于四位数并且这九个数都不重复
time /tmp/a.out > a.txt
real 0m0.004s
user 0m0.000s
sys 0m0.000s
cat -n a.txt
1 12×483=5796 124835796
2 12×695=8340 126958340
3 13×406=5278 134065278
4 13×546=7098 135467098
5 13×604=7852 136047852
6 13×754=9802 137549802
7 15×326=4890 153264890
8 15×486=7290 154867290
9 15×492=7380 154927380
10 15×632=9480 156329480
11 15×648=9720 156489720
12 18×297=5346 182975346
13 18×392=7056 183927056
14 18×409=7362 184097362
15 19×204=3876 192043876
16 19×253=4807 192534807
17 19×402=7638 194027638
18 19×453=8607 194538607
19 23×196=4508 231964508
20 26×345=8970 263458970
21 27×198=5346 271985346
22 28×157=4396 281574396
23 32×169=5408 321695408
24 34×178=6052 341786052
25 34×185=6290 341856290
26 38×159=6042 381596042
27 39×186=7254 391867254
28 42×138=5796 421385796
29 48×159=7632 481597632
30 48×165=7920 481657920
31 54×168=9072 541689072
32 59×108=6372 591086372
33 59×136=8024 591368024
34 63×154=9702 631549702
35 69×108=7452 691087452
real 0m0.004s
user 0m0.000s
sys 0m0.000s
cat -n a.txt
1 12×483=5796 124835796
2 12×695=8340 126958340
3 13×406=5278 134065278
4 13×546=7098 135467098
5 13×604=7852 136047852
6 13×754=9802 137549802
7 15×326=4890 153264890
8 15×486=7290 154867290
9 15×492=7380 154927380
10 15×632=9480 156329480
11 15×648=9720 156489720
12 18×297=5346 182975346
13 18×392=7056 183927056
14 18×409=7362 184097362
15 19×204=3876 192043876
16 19×253=4807 192534807
17 19×402=7638 194027638
18 19×453=8607 194538607
19 23×196=4508 231964508
20 26×345=8970 263458970
21 27×198=5346 271985346
22 28×157=4396 281574396
23 32×169=5408 321695408
24 34×178=6052 341786052
25 34×185=6290 341856290
26 38×159=6042 381596042
27 39×186=7254 391867254
28 42×138=5796 421385796
29 48×159=7632 481597632
30 48×165=7920 481657920
31 54×168=9072 541689072
32 59×108=6372 591086372
33 59×136=8024 591368024
34 63×154=9702 631549702
35 69×108=7452 691087452
昨天晚上写的 答案是多少个啊。。
程序代码:
#include <stdio.h> int isOK(int a) { int i = 0; int x = 0; int add = 0; int xor = 0; /* 12 345 6789 */ for (i = 0; i < 9; i++) { x = a % 10; a /= 10; x = 1 << x; /* change to bin */ xor ^= x; add += x; } /* e.g., for bin, 10(2)+11(2) = 5 > 10(2)^11(2) = 1 while 01(2)+10(2) == 01(2)^10(2) */ if (add == xor) { return 1; } return 0; } int main(void) { unsigned int x = 0; unsigned int y = 0; unsigned int result = 0; for (x = 10; x < 100; x++) { for (y = 100; y < 1000; y++) { result = x * y; if (result < 10000 && result >= 1000) { if (isOK(x*10000000+y*10000+result)) { printf("%d×%d=%d\t%d\n", x, y, result, x*10000000+y*10000+result); } } } } return 0; }
应该一看就懂 我也是写错了一次才琢磨出这个办法的。。
[ 本帖最后由 zklhp 于 2013-4-14 11:51 编辑 ]