两个大整数相加
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) //多组输入
{
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(a+b);
}
}
}
多个大整数相加
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
int n=cin.nextInt();
Object obj=BigInteger.ZERO;
for(int i=0;i<n;i++)
{
BigInteger sum=BigInteger.ZERO;
while(true)
{
BigInteger b=cin.nextBigInteger();
if(b.equals(obj))
{
System.out.println(sum);
if(i!=n-1)
System.out.println();
break;
}
sum=sum.add(b);
}
}
}
}
}
大整数取模
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
BigInteger ans = in.nextBigInteger();
BigInteger mod = in.nextBigInteger();
System.out.println(ans.remainder(mod));
}
}
}