__int 128用法 (可以处理约 1e38 范围内的数)

    1. inline __int128 read() {
    2. __int128 x=0,f=1;
    3. char ch=getchar();
    4. while(ch<'0'||ch>'9') {
    5. if(ch=='-')
    6. f=-1;
    7. ch=getchar();
    8. }
    9. while(ch>='0'&&ch<='9') {
    10. x=x*10+ch-'0';
    11. ch=getchar();
    12. }
    13. return x*f;
    14. }
    15. inline void print(__int128 x) {
    16. if(x<0) {
    17. putchar('-');
    18. x=-x;
    19. }
    20. if(x>9)
    21. write(x/10);
    22. putchar(x%10+'0');
    23. }

    JAVA大数类实现

    1. import java.math.BigInteger;
    2. import java.io.*;
    3. public class Main {
    4. public static void main(String[] args) throws IOException {
    5. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    6. BigInteger a = new BigInteger(reader.readLine());
    7. BigInteger b = new BigInteger(reader.readLine());
    8. System.out.println(a.add(b));
    9. System.out.println(a.subtract(b));
    10. System.out.println(a.multiply(b));
    11. System.out.println(a.divide(b));
    12. System.out.println(a.mod(b));
    13. reader.close();
    14. }
    15. }