正整数のゲーデル数化?
Posted feedbacks - Java
とりあえず,「仕様バグ」は無視して題意どおりの実装。 $ java Goedel 230 108 $ java Goedel 123456789 52713275010243038997421106186697438702252144407250
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.math.BigInteger;
import java.util.Vector;
public class Goedel {
private static final int CERTAINTY = 24;
public static void main(String[] args) throws Exception {
Vector<BigInteger> primes = new Vector<BigInteger>();
for (int i = 2; primes.size() < args[0].length(); i++) {
BigInteger bi = BigInteger.valueOf(i);
if (bi.isProbablePrime(CERTAINTY)) primes.add(bi);
}
BigInteger result = BigInteger.ONE;
for (int i = 0; i < args[0].length(); i++)
result = result.multiply(primes.get(i).pow(Integer.valueOf(args[0].substring(i,i+1))));
System.out.println(result);
}
}
|


nobsun
#4420()
Rating2/2=1.00
see: ゲーデル数
[ reply ]