2019年10月28日月曜日

最近発見された3つの立方数の和が42になる数

掲題の件を CentOS8 の gawk で確認してみた。
-M オプション(MPFR / MP 拡張)が必要なので、CentOS7 以下では駄目でした。
[root@hoge ~]# uname -a
Linux hoge 4.18.0-80.el8.x86_64 #1 SMP Wed Mar 13 12:02:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@hoge ~]# gawk --version
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.6-p2, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2018 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
[root@hoge ~]# cat 42.gawk 
BEGIN {
 a = -80538738812075974
 b =  80435758145817515
 c =  12602123297335631

 printf("a = %18d    length=%d\n", a, length(-a))
 printf("b = %18d    length=%d\n", b, length(b))
 printf("c = %18d    length=%d\n", c, length(c))
 print ""

 x = a^3
 y = b^3
 z = c^3

 printf("a^3 = %52d    length=%d\n", x, length(-x))
 printf("b^3 = %52d    length=%d\n", y, length(y))
 printf("c^3 = %52d    length=%d\n", z, length(z))
 print ""

 printf("a^3 + b^3 + c^3 = %d\n", x + y + z)

 exit(0)
}
[root@hoge ~]# time gawk -M -f 42.gawk 
a = -80538738812075974    length=17
b =  80435758145817515    length=17
c =  12602123297335631    length=17

a^3 = -522413599036979150280966144853653247149764362110424    length=51
b^3 =  520412211582497361738652718463552780369306583065875    length=51
c^3 =    2001387454481788542313426390100466780457779044591    length=49

a^3 + b^3 + c^3 = 42

real 0m0.002s
user 0m0.000s
sys 0m0.001s
恐ろしい桁数ですが、このように計算は一瞬でした。

0 件のコメント:

コメントを投稿

人気ブログランキングへ にほんブログ村 IT技術ブログへ