JavaScript
fig.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pre id="output"></pre>
<script>
"use strict";
onload = function() {
let log = "";
let a = "3";
let b = "3";
for (let i = 0; i < 20; i++) {
const c = BigInt(a) * BigInt(b);
log += `${i+1}: ${a} * ${b} = ${c}\n`;
a = "2" + a;
b = "4" + b;
}
output.textContent = log;
};
</script>
</body>
</html>
Python
Python 3ではintに上限はない模様。
fig.py
# Python 3
a = "3"
b = "3"
for i in range(20):
c = int(a) * int(b)
print(f"{i+1}: {a} * {b} = {c}")
a = "2" + a
b = "4" + b
Decimalの例
fig.py
# Python 3
from decimal import Decimal, getcontext
getcontext().prec = 40
a = "3"
b = "3"
for i in range(20):
c = Decimal(a) * Decimal(b)
print(f"{i+1}: {a} * {b} = {c}")
a = "2" + a
b = "4" + b
C++
fig.cpp
// C++(gcc)
#include <iostream>
#include <boost/format.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
int main(void)
{
string a = "3";
string b = "3";
for (int i = 0; i < 20; i++) {
auto c = Bint(a) * Bint(b);
cout << (boost::format("%1%: %2% * %3% = %4%") % (i+1) % a % b % c)
<< endl;
a = "2" + a;
b = "4" + b;
}
}
C#
fig.cs
// C#(.NET Core)
using System;
using System.Numerics;
class Program {
static void Main(string[] args) {
var a = "3";
var b = "3";
for (var i = 0; i < 20; i++) {
var c = BigInteger.Parse(a) * BigInteger.Parse(b);
Console.WriteLine($"{i+1}: {a} * {b} = {c}");
a = "2"+ a;
b = "4"+ b;
}
}
}
Java
BigInteger:整数
BigDecimal:10進の実数
fig.java
// Java(OpenJDK 8)
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
String a = "3";
String b = "3";
for (int i = 0; i < 20; i++) {
BigInteger c = new BigInteger(a).multiply(new BigInteger(b));
System.out.printf("%d: %s * %s = %s\n", i+1, a, b, c);
a = "2" + a;
b = "4" + b;
}
}
}
BigDecimalの例
fig.java
// Java(OpenJDK 8)
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
String a = "3";
String b = "3";
for (int i = 0; i < 20; i++) {
BigDecimal c = new BigDecimal(a).multiply(new BigDecimal(b));
System.out.printf("%d: %s * %s = %s\n", i+1, a, b, c);
a = "2" + a;
b = "4" + b;
}
}
}