zoukankan      html  css  js  c++  java
  • 高精度 java的一些题

    poj 1001 Exponentiation

    import java.util.*;
    import java.math.*;
    public class Main {
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		while(in.hasNextBigDecimal()) {
    			BigDecimal a = in.nextBigDecimal();
    			int b = in.nextInt();
    			a = a.pow(b);
    			a = a.stripTrailingZeros();
    			String ans = a.toPlainString();
    			if(ans.startsWith("0."))
    				ans = ans.substring(1);
    			System.out.println(ans);
    		}
    
    	}
    
    }
    
    

    poj 1503 Integer Inquiry

    大数加法

    ``` import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); BigInteger a, b, c; c = BigInteger.valueOf(0); b = BigInteger.valueOf(0); while(true) { a = in.nextBigInteger(); if(a.equals(c)) break; b = b.add(a); } System.out.println(b); }

    }

    <h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1042", target = "_blank">hdu 1042 N! </a> </h3>
    <h3> 大数乘法 </h3>
    

    import java.util.;
    import java.math.
    ;
    public class Main {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    BigInteger ans, c;
    while(in.hasNextInt()) {
    int n = in.nextInt();
    ans = BigInteger.valueOf(1);
    for(int i = n; i >= 1; i--) {
    c = BigInteger.valueOf(i);
    ans = ans.multiply(c);
    }
    System.out.println(ans);
    }
    }

    }

    
    <h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1316", target = "_blank">hdu 1316 How Many Fibs? </a> </h3>
    <h3> 大数乘法, 求给出的两个数之间有多少个fib数</h3>
    

    import java.util.;
    import java.math.
    ;
    public class Main {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    BigInteger f[] = new BigInteger[505];
    f[1] = new BigInteger("1");
    f[2] = new BigInteger("2");
    for(int i = 3; i<= 500; i++) {
    f[i] = f[i-1].add(f[i-2]);
    }
    BigInteger a, b, zero;
    zero = BigInteger.valueOf(0);
    while(true) {
    a = in.nextBigInteger();
    b = in.nextBigInteger();
    if(a.equals(zero) && b.equals(zero)) {
    break;
    }
    int tmp = 0;
    for(int i = 1; i <= 500; i++) {
    if(f[i].compareTo(a)>=0 && f[i].compareTo(b)<=0)
    tmp++;
    }
    System.out.println(tmp);
    }
    }

    }

  • 相关阅读:
    Stream流的使用
    ThreadLocal原理和使用场景?
    Python+Appium实现APP自动化测试
    查看Linux系统版本信息
    linux命令之修改yum源为国内镜像
    lsb_release: command not found 解决
    docker安装mysql
    win10 系统出现“你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问。”
    python常用sys模块
    python常用os模块
  • 原文地址:https://www.cnblogs.com/yohaha/p/5331163.html
Copyright © 2011-2022 走看看