我们如何解决具有N的方程!其中的常量,其中N可以是范围1 <= N <= 10 ^ 6 BigInteger最多只能执行128位?
即使在双方都做对数时,它也会留下比BigInteger更大的值.
我必须使用以下语句将biginteger写入文本文件.
out.writeObject(n1);
Run Code Online (Sandbox Code Playgroud)
其中我的n1是长度为512位的大整数.
从文本文件中读取相同的对象给我一个不同的值n1.任何人都可以帮我解决这个问题.用于读取值的语句是:
in.readObject();
Run Code Online (Sandbox Code Playgroud)
提前致谢.
为什么这个数学返回一些数字的负数:
int x = 351;
String bigValue= ((50*x*x*x-150*x*x+400*x)/3) + "";
BigInteger resultInteger = new BigInteger(bigValue);
System.out.println(resultInteger);
Run Code Online (Sandbox Code Playgroud)
结果 - > 714612600
但如果我使用352
结果 - > -710900565
对于x = 500 - > 639244234
为什么?
我正在尝试转换10000000000000000000000000000000为BigInteger。但是它没有转换。我的代码是
BigInteger number = BigInteger.valueOf(10000000000000000000000000000000);
它正在显示The literal 10000000000000000000000000000000 of type int is out of range。
有什么方法可以转换此数字,因为我必须在程序中将此数字用作整数?
我创建了一个包含BigInteger对象的数组.当我想为数组分配数字时,我得到一个找不到符号的错误.你能帮助我吗?那是代码:
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Solution
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int t1= in.nextInt();
int t2= in.nextInt();
int n= in.nextInt();
BigInteger[] arr = new BigInteger[n];
arr[0] = new BigInteger.valueOf(t1);
arr[1] = new BigInteger.valueOf(t2);
}
}
Run Code Online (Sandbox Code Playgroud)
输入值为0 1 5.这是错误:
Solution.java:15: error: cannot find symbol
arr[0] = new BigInteger.valueOf(t1);
^
symbol: class valueOf
location: class BigInteger
Solution.java:16: error: cannot find symbol
arr[1] = new BigInteger.valueOf(t2);
^
symbol: class valueOf
location: class …Run Code Online (Sandbox Code Playgroud) 我不认为我必须写它,但我在任何地方都找不到至少一个减去大数的例子
所以我有两个数字,我想将它们相减,库说内存只有限制,但是,当我尝试减去两个 256 位数字时,我收到错误。
告诉我该怎么办以及如何解决?我开始学习Go,一切看起来都是那么的酷,然而我却不断遇到类似的问题。怎么了.......
package main
import (
"fmt"
"math/big"
)
func main() {
a := big.NewInt(113792089237316195423570985008687907853269984665640564039457584007908834671645)
b := big.NewInt(20277110887056303803699431755396003735040374760118964734768299847012543114150)
c := big.NewInt(0).Sub(a, b)
fmt.Println("c =", c)
}
Run Code Online (Sandbox Code Playgroud)
输出:
*prog.go:9:18: constant 113792089237316195423570985008687907853269984665640564039457584007908834671645 overflows int64
prog.go:10:18: constant 20277110887056303803699431755396003735040374760118964734768299847012543114150 overflows int64*
Run Code Online (Sandbox Code Playgroud)
我使用的是 go 版本 go1.12.4 linux/amd64
操场上的这段代码: https ://play.golang.org/p/AY8Z8kkCRdg
import java.math.BigInteger;
public class GaayuProbOne {
static void power(int N, int P) {
BigInteger result = new BigInteger("10");
BigInteger res = result.pow(P);
System.out.println(res);
}
static double power1(int N, int P) {
double res =Math.pow(N,P);
return res;
}
public static void main(String[] args) {
int N = 10;
double P = 25*power1(10,25);
System.out.println(P);
int q = (int) P;
power(N, q);
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码是java中计算10 25 10 25的程序。
如何计算呢?
线程“主”java 中的异常。郎。算术异常:大整数会溢出支持的范围
有没有在java程序中计算10 25 10 25的方法?
我有一个代码可以为BigInteger分配null.我需要检查它是否为空.
我尝试过以下的东西,它们不起作用:
== 只会检查参考,而不是值.
BigInteger x = BigInteger.ONE;
if(x== null)
{
System.out.println( x );
}
Run Code Online (Sandbox Code Playgroud)以上输出是打印x.(不管怎样,布尔条件都满足,即使x不为null).
以下在比较时给出NullPointerException
BigInteger x = BigInteger.ONE;
BigInteger myNull = null;
if(x.compareTo(myNull) == 0 )
{
System.out.println( x );
}
Run Code Online (Sandbox Code Playgroud)另一个NPE:
BigInteger x = BigInteger.ONE;
if(x.compareTo(null) == 0)
{
System.out.println( x );
}
Run Code Online (Sandbox Code Playgroud)如何检查BigInteger是否正确?
我有这个代码:
if ((x & y)==0){
// do this...
}
Run Code Online (Sandbox Code Playgroud)
我想实现相同的效果,但使用BigInteger而不是int.
我试过这个:
if ((x.compareTo(BigInteger.ZERO)==0)&&(y.compareTo(BigInteger.ZERO)==0)){
// do this...
}
Run Code Online (Sandbox Code Playgroud)
但是,现在,我的程序永远不会进入这个if语句.我将衷心感谢您的帮助.
此外,这是整个代码.
import java.math.*;
public class mew {
public static void main (String[] args) {
BigInteger two = BigInteger.valueOf(2);
BigInteger num = two.pow(100);
BigInteger i = BigInteger.valueOf(0);
while (i.compareTo(num) < 0){
BigInteger mask = num;
while (mask.compareTo(BigInteger.ZERO) > 0){
if ((mask.compareTo(BigInteger.ZERO)==0)&&(i.compareTo(BigInteger.ZERO)==0)){
System.out.print("0");
}
else {
System.out.print("1");
}
mask = mask.shiftRight(1);
}
System.out.println();
i = i.add(BigInteger.valueOf(1));
}
}
}
Run Code Online (Sandbox Code Playgroud)
目的是打印n长位串的所有可能排列.我应该参考我的想法和实现:Java:如何输出所有可能的二进制组合(256个不同的序列)?看到nikis的帖子.
我必须用另一个 BigInteger 数字来 pow 一个 bigInteger 数字。
不幸的是,只允许使用一个 BigInteger.pow(int)。
我不知道如何解决这个问题。