私が計算している数字は大きすぎて収まらないので、ロングはそれをカットしないことがわかりました。BigInts の概念に苦労しています。
実行する次の方程式があるとしましょう。
int p = 11549
int n = 252817
式は次のとおりです.. : (数値 * p )^ (i 乗)%n .
私がやったロングで:
long number;
long p;
long n;
long temp;
long total;
for (int i=0; i<6;i++) {
temp = numer*Math.pow(p,i);
total += temp;
}
total %= n;
しかし、Math.pow を使用すると、このメソッドを使用するには数値が膨大になり、BigIntegers を使用する必要があります。どうすればできるのかわかりません。今、私はこれを手に入れました:(電源オフステートメントを理解できるまで%がありません。)
long temp;
long p;
BigInteger opphoyd;
BigInteger mod;
for (int i=0;i<6;i++) {
temp = number * p;
opphoyd = BigInteger.valueOf(temp);
mod = BigInteger.valueOf(i);
mod.add(opphoyd.pow(i));
mod.add(opphoyd);
System.out.println(mod);
}
しかし、まったく機能していません。誰かが私を正しい方向に向けることができますか?