• java 大数 以后遇到了再添加吧~ ^ _ ^


    hdu 1316  How Many Fibs?

     1 import java.math.BigInteger;
     2 import java.util.Scanner;
     3 
     4 public class Main {
     5     public static void main(String[] args) {
     6         Scanner sc =new Scanner(System.in);
     7         BigInteger f[]=new BigInteger[530];
     8         f[1]=new BigInteger("1");
     9         f[2]=new BigInteger("2");
    10         for(int i=3;i<=520;i++)
    11         {
    12             f[i]=f[i-2].add(f[i-1]);
    13             //System.out.println(i+"   "+f[i]);
    14         }        
    15         while(sc.hasNextBigInteger())
    16         {
    17             BigInteger n,m,zero;
    18             zero=new BigInteger("0");
    19             n=sc.nextBigInteger();
    20             m=sc.nextBigInteger();
    21             if(n.compareTo(zero)==0&&m.compareTo(zero)==0)
    22                 break;
    23             int left=1,right=520,mid=0;
    24             int best=100000;
    25             while(left<=right)
    26             {
    27                 
    28                 mid=(left+right)/2;
    29                if(f[mid].compareTo(n)>=0)
    30                 {
    31                    if(mid<best)
    32                        best=mid;
    33                     right=mid-1;
    34                     
    35                 }
    36                 else
    37                 {
    38                     left=mid+1;
    39                 }        
    40             }
    41             int ansl,ansr;
    42             ansl=best;        
    43             left=0;right=520;
    44              best=0;
    45             while(left<=right)
    46             {
    47                 
    48                 mid=(left+right)/2;
    49             
    50                 if(f[mid].compareTo(m)<=0)
    51                 {
    52                     if(best<mid)
    53                         best=mid;
    54                     left=mid+1;
    55                     
    56                 }
    57                 else
    58                 {
    59                     right=mid-1;
    60                 }        
    61             }
    62             ansr=best;
    63             System.out.println(ansr-ansl+1);    
    64             //System.out.println(ansl);    
    65             //System.out.println(ansr);                            
    66         }        
    67     }
    68 }

     hdu 1063    n^m舍去多余的0

     1 import java.math.BigDecimal;
     2 import java.math.BigInteger;
     3 import java.util.Scanner;
     4 
     5 
     6 public class Main {
     7     public static void main(String[] args) {
     8         BigDecimal n,ans;
     9        
    10         Scanner sc=new Scanner(System.in);
    11         while(sc.hasNextBigDecimal())
    12         {
    13             int m;
    14             n=sc.nextBigDecimal();
    15             m=sc.nextInt();
    16             ans=new BigDecimal("1");
    17             for(int i=0;i<m;i++)
    18                 ans=ans.multiply(n);
    19             ans=ans.stripTrailingZeros();
    20             String str=ans.toPlainString();
    21             if(str.startsWith("0."))
    22                 str=str.substring(1);       //以从1开始的子串为新串
    23 System.out.println(str); 24 25 26 27 } 28 29 30 31 } 32 33 }

    hdu 1047

     1 import java.math.BigInteger;
     2 import java.util.Scanner;
     3 
     4 
     5 public class Main {
     6     public static void main(String[] args) {
     7         BigInteger ans,n,one,i,zero,m;
     8         Scanner sc=new Scanner(System.in);
     9         n=sc.nextBigInteger();
    10         zero=new BigInteger("0");
    11         
    12         one=new BigInteger("1");
    13         while(n.compareTo(zero)>0)
    14         {
    15             ans=new BigInteger("0");            
    16             while(true)
    17             {
    18                 m=sc.nextBigInteger();
    19                 if(m.compareTo(zero)==0)
    20                     break;
    21                 ans=ans.add(m);
    22             }
    23             System.out.println(ans);
    24             n=n.subtract(one);
    25             if(n.compareTo(zero)!=0)
    26                 System.out.println("");
    27             
    28         }
    29         
    30         
    31     }
    32 
    33 }

    hdu 1042

     1 //package 大数;
     2 
     3 import java.math.BigInteger;
     4 import java.util.Scanner;
     5 
     6 
     7 public class Main {
     8     
     9     public static void main(String[] args) {
    10         BigInteger ans,i,n,one;
    11         Scanner sc=new Scanner(System.in);
    12         while(sc.hasNextBigInteger())
    13         {
    14             n=sc.nextBigInteger();
    15             one=new BigInteger("1");
    16             ans=new BigInteger("1");
    17             i=new BigInteger("1");
    18             
    19             while(i.compareTo(n)<=0)
    20             {
    21             
    22             
    23                 ans=ans.multiply(i);
    24                 
    25                 i=i.add(one);
    26                 
    27                 
    28             }
    29             System.out.println(ans);
    30             
    31         }
    32     }
    33 
    34 }
  • 相关阅读:
    java 获取两个日期相差的毫秒数
    list 去重复
    java日期处理 calendar 和date
    CSS文字超出div或者span时显示省略号
    null类型的字段加1
    CSS或者JS实现鼠标悬停显示另一元素
    去除空格的js 和 使用正则表达式替换
    php preg_replace正则表达式除去<a>
    PHP页面编码问题
    用php生成09,az
  • 原文地址:https://www.cnblogs.com/assult/p/3848467.html
Copyright © 2020-2023  润新知