假设用GNU的大整数library,所有int变量都可以是任意大的自然数。其中用print的那一行有可能造成0除以0,在C里面整数0除以0程序要crash的。请问这个程序会crash吗?如果你知道会不会,你就知道了哥猜想对不对。
存在类似的程序,它不需要任何外界输入,运行过程是决定地而且唯一的,但是连数学家都不可能知道它会不会crash。有意思吧?
int is_prime(int x) {
for (int i = 2; i*i
if (mod(x, i) == 0) { // i divides x, not a prime
return 0;
}
}
return 1;
}
void test_goldbach() {
for (int n = 6; ; n = n + 2) { // Iterate over even numbers n.
for (int x = 2; x
if (!is_prime(x)) {
continue;
}
for (int y = 2; y
if (!is_prime(y)) {
continue;
}
// Now we have x and y prime numbers.
// If x + y == n, we test the next n.
if (x + y == n) {
goto next_n;
}
}
}
next_n:;
// By construction of the loops, if n invalides Goldbach,
// then x == y == n, and (n - x) / (n - y) will crash
// with a division by 0 error.
// Otherwise, the code can go on.
print((n - x) / (n - y));
}
}
给一个具体的软件,你们看看会不会crash?
所有跟帖:
•
這問題不難證明,我想了一下就得出答案
-tsc12-
♂
(84 bytes)
()
02/28/2010 postreply
18:14:02
•
没读第一行吗?
-UberAlles-
♂
(23 bytes)
()
02/28/2010 postreply
18:23:01
•
沒有一部電腦整數可以無限增加的,你連這都不懂
-tsc12-
♂
(0 bytes)
()
02/28/2010 postreply
18:45:34
•
你事先不知道任何电脑的升级上限,道理就这么简单。
-UberAlles-
♂
(214 bytes)
()
02/28/2010 postreply
19:59:26
•
哪有人写个程序不知道在哪run啊?您是Java程序员吧?program once, debug everywhere
-先想一想再说-
♂
(0 bytes)
()
02/28/2010 postreply
20:19:08
•
我终于明白您的逻辑了,您觉得一个bug free的程序是放之四海而皆run的啊?
-先想一想再说-
♂
(34 bytes)
()
02/28/2010 postreply
20:22:17
•
本来就是计算理论的东西,当然要放之四海皆准。
-UberAlles-
♂
(56 bytes)
()
02/28/2010 postreply
20:37:25
•
软件都有特定运行平台,脱离运行平台探讨软件无异于无本之木,无源之水
-先想一想再说-
♂
(0 bytes)
()
02/28/2010 postreply
20:39:39
•
我早就說過學數學的是在象牙塔裡看世界
-tsc12-
♂
(206 bytes)
()
02/28/2010 postreply
20:51:43
•
你没有明白他的意思,太令人遗憾。可计算理论是计算机科学的基础
-企鹅肥肥-
♂
(16 bytes)
()
03/03/2010 postreply
01:34:37
•
另外不管计算机如何升级,一个躺着的8比他所能处理的数大躺着的8那么多倍
-先想一想再说-
♂
(0 bytes)
()
02/28/2010 postreply
20:31:32