zoukankan      html  css  js  c++  java
  • HDU 1715 大菲波数(JAVA, 简单题,大数)

    题目

    //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数

    import java.io.*;
    import java.util.*;
    import java.math.*;
    
    public class Main {
    
        /**
         * @xqq
         */
        public BigInteger an(BigInteger a, BigInteger b, int n) {
            if(n == 1) {
                return a;
            }
            for(int i = 2; i < n; i++) {
                BigInteger c = a.add(b);
                a = b;
                b = c;
            }
            return b;
        }
        public static void main(String[] args)    throws Exception {
            // 定义并打开输入文件
            Scanner cin = new Scanner(System.in);
            
            Main e = new Main();
            int t, n;
            BigInteger a = BigInteger.valueOf(1);
            BigInteger b = BigInteger.valueOf(2);
            
            t = cin.nextInt();
            for(int i = 0; i < t; i++) {
                n = cin.nextInt() ; 
                System.out.println(e.an(a, b, n));
            }
            
            cin.close();  //关闭输入文件
        }
    }
    View Code
    一道又一道,好高兴!
  • 相关阅读:
    502 bad gateway错误的网关
    nodejs发展
    edgejs
    websocket nodejs实例
    nodejs原码
    node案例
    node 与php整合
    node c#
    jquery
    express
  • 原文地址:https://www.cnblogs.com/laiba2004/p/3702591.html
Copyright © 2011-2022 走看看