码迷,mamicode.com
首页 > 编程语言 > 详细

java大数习题

时间:2020-04-26 10:56:20      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:next   for   ati   math   cin   scan   http   加法   ted   

大数加法,题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002

import java.math.BigInteger;

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        int count = 1;
        n = sc.nextInt();
        int t=n;
        while (t> 0) {
            BigInteger a = sc.nextBigInteger();
            BigInteger b = sc.nextBigInteger();
            System.out.println("Case " + count+":");
            System.out.println(a + " + " + b + " = " + a.add(b));
            t--;
            if(count!=n)
                System.out.println();
            count++;

        }
    }
}

大数判断(带小数,重要的题目):题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            BigDecimal a=sc.nextBigDecimal();
            BigDecimal b=sc.nextBigDecimal();
            if(a.compareTo(b)==0) {
                System.out.println("YES");
            }
            else
                System.out.println("NO");
            
        }
    }
}

大数阶层,题目链接:http://acm.jlnu.edu.cn/problem.php?id=1130

import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        BigInteger n=new BigInteger("1");
        for (int i = 2; i <= 1977; ++i) {
            n = n.multiply(BigInteger.valueOf(i));
        }
            System.out.println(n);
    }
}

大斐波那契,题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1715

import java.math.BigInteger;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin = new Scanner(System.in);
        
        BigInteger[] nums = new BigInteger[1010];
        nums[1] = new BigInteger("1");
        nums[2] = new BigInteger("1");
        for(int i = 3; i <= 1000; i++)
            nums[i] = nums[i - 1].add(nums[i - 2]);
        
        int T = cin.nextInt();
        while(T > 0)
        {
            T--;
            int n = cin.nextInt();
            System.out.println(nums[n]);
        }

    }

}

java大数习题

标签:next   for   ati   math   cin   scan   http   加法   ted   

原文地址:https://www.cnblogs.com/julyzqy/p/12777449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!