HDU中大數實現的題目,持續更新(JAVA實現)

來源:互聯網
上載者:User

標籤:

HDU1002:大數加法,PE了N次

import java.util.Scanner;import java.math.*;public class Main{    public static void main(String[] args)    {        Scanner cin = new Scanner(System.in);        int T;        T=cin.nextInt();        for(int z=1;z<=T;z++)        {            if(z!=1) System.out.println();            BigInteger a,b;            a=cin.nextBigInteger();            b=cin.nextBigInteger();            System.out.println("Case "+z+":");            System.out.println(a+" + "+b+" = "+a.add(b));                    }        cin.close();    }}
View Code

HDU1042:N!大數乘法

import java.util.Scanner;import java.math.*;import javax.naming.ldap.HasControls;public class Main{    public static void main(String[] args)    {        Scanner cin = new Scanner(System.in);        int t;        while(cin.hasNext())        {            BigInteger n=BigInteger.valueOf(1);            t=cin.nextInt();            for(int i=2;i<=t;i++)            {                n=n.multiply(BigInteger.valueOf(i));            }            System.out.println(n);        }            }        }
View Code

HDU1316:How Many Fibs?

import java.math.*;import java.util.Scanner;public class Main {    public static void main(String[] args)      {        Scanner cin = new Scanner(System.in);        BigInteger []f=new BigInteger[1020];        f[0]=BigInteger.valueOf(1);        f[1]=BigInteger.valueOf(1);        f[2]=BigInteger.valueOf(2);        for(int i=3;i<1019;i++)            f[i]=f[i-1].add(f[i-2]);        BigInteger a,b;        int sum;        while(cin.hasNextBigInteger())        {            a=cin.nextBigInteger();            b=cin.nextBigInteger();            if(a.compareTo(BigInteger.ZERO)==0&&b.compareTo(BigInteger.ZERO)==0) break;            sum=0;            for(int i=1;i<=1015;i++)            {               if(f[i].compareTo(a)>=0&&f[i].compareTo(b)<=0)               {                  sum++;               }               if(f[i].compareTo(b)>0) break;            }            System.out.println(sum);        }        cin.close();    }}

HDU1753: 大明 A+B 大數加法加一些函數

import java.math.*;import java.util.Scanner;public class Main {    public static void main(String[] args)      {        Scanner cin = new Scanner(System.in);        BigDecimal a,b;        while(cin.hasNextBigDecimal())        {            a=cin.nextBigDecimal();            b=cin.nextBigDecimal();            System.out.println(a.add(b).stripTrailingZeros().toPlainString());        }        cin.close();    }}

 

HDU中大數實現的題目,持續更新(JAVA實現)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.