標題:
BigInteger 大數運算
[打印本頁]
作者:
tonyh
時間:
2021-10-16 15:12
標題:
BigInteger 大數運算
本帖最後由 tonyh 於 2021-10-16 15:15 編輯
[attach]12082[/attach]
import java.math.BigInteger;
public class P6 {
BigInteger x=new BigInteger("1999999999999999999999999999999999999999999999999");
BigInteger y=new BigInteger("1000000000000000000000000000000000000000000000001");
BigInteger i=new BigInteger("2100000000000000000000000000000000000000000000000");
BigInteger j=new BigInteger("1400000000000000000000000000000000000000000000000");
long a=1999999999999999999l;
long b=1000000000000000001l;
P6()
{
System.out.println(a+b);
System.out.println(x.add(y));
System.out.println(x.subtract(y));
System.out.println(x.multiply(BigInteger.valueOf(2)));
System.out.println(x.divide(y));
System.out.println(x.remainder(y));
System.out.println(i.gcd(j));
System.out.println(j.pow(2));
}
public static void main(String[] args){
new P6();
}
}
複製代碼
作者:
蔡幸融
時間:
2021-10-30 15:15
import java.math.BigDecimal;
import java.math.BigInteger;
public class Ch01 {
Ch01()
{
BigInteger a=new BigInteger("45000000000000000000000000000000000000000");
BigInteger b=new BigInteger("4567683213245657895453612354679545666666666665555553");
BigInteger c=new BigInteger("55000000000000000000000000000000000000000");
long x=12000000000l;
long y=53000000000l;
System.out.println(x+y);
System.out.println(a.add(b));
System.out.println(a.subtract(b));
System.out.println(a.multiply(b));
System.out.println(a.divide(b));
System.out.println(a.remainder(b));
System.out.println(a.gcd(b));
System.out.println(a.pow(20));
}
public static void main(String[] args) {
new Ch01();
}
}
複製代碼
作者:
洪藜芸
時間:
2021-10-30 15:17
import java.math.BigInteger;
public class C2 {
BigInteger a=new BigInteger("12345678987654321012345678987654321");
BigInteger b=new BigInteger("98765432101234567898765432123456789");
BigInteger c=new BigInteger("74102589636985201474102589636985201");
BigInteger d=new BigInteger("98700000000000000000000000000000000");
BigInteger e=new BigInteger("10239999999999999999999999999999999");
BigInteger f=new BigInteger("55555555555555555555555555555555555");
BigInteger g=new BigInteger("2177852000000000000000000000000000000000000000");
long l=1999999999999999999l;
long y=9223372030000000000l;
C2()throws Exception
{
System.out.println(l+y);
System.out.println(a.add(b));
System.out.println(b.subtract(c));
System.out.println(c.multiply(BigInteger.valueOf(2)));
System.out.println(d.divide(e));
System.out.println(e.remainder(f));
System.out.println(f.gcd(g));
System.out.println(g.pow(2));
}
public static void main(String[] args)throws Exception{
new C2();
}
}
複製代碼
作者:
蔡依宸
時間:
2021-10-30 15:18
import java.math.BigInteger;
public class WayV {
BigInteger x=new BigInteger("1999999999999999999999999999999999999999999999999999999999");
BigInteger y=new BigInteger("10000000000000000000000000000000000000000000001");
BigInteger i=new BigInteger("2100000000000000000000000000000000000000000000000");
BigInteger j=new BigInteger("1400000000000000000000000000000000000000000000000");
long a=1999999999999999999l;
long b=1000000000000000001l;
WayV()
{
System.out.println(a+b);
System.out.println(x.add(y));
System.out.println(x.subtract(y));
System.out.println(x.multiply(BigInteger.valueOf(2)));
System.out.println(x.divide(y));
System.out.println(x.remainder(y));
System.out.println(i.gcd(j));
System.out.println(j.pow(2));
}
public static void main(String[] args) {
new WayV();
}
}
複製代碼
作者:
蔡季庭
時間:
2021-10-30 15:19
import java.math.BigInteger;
public class Big {
BigInteger x=new BigInteger("1999999999999999999999999999999999999999999999999");
BigInteger y=new BigInteger("1000000000000000000000000000000000000000000000001");
BigInteger i=new BigInteger("2100000000000000000000000000000000000000000000000");
BigInteger j=new BigInteger("1400000000000000000000000000000000000000000000000");
long a=1999999999999999999l;
long b=1000000000000000001l;
Big()
{
System.out.println(a+b);
System.out.println(x.add(y));
System.out.println(x.subtract(y));
System.out.println(x.multiply(BigInteger.valueOf(2)));
System.out.println(x.divide(y));
System.out.println(x.remainder(y));
System.out.println(i.gcd(j));
System.out.println(j.pow(2));
}
public static void main(String[] args){
new Big();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2