POJ1942+找规律
View Code
1 import java.util.*; 2 import java.math.*; 3 import java.text.*; 4 import java.io.* ; 5 6 public class Main{ 7 public static void main( String args[] ){ 8 BigInteger n,m,tq; 9 Scanner cin = new Scanner(new BufferedInputStream(System.in)); 10 while( cin.hasNext() ){ 11 n = cin.nextBigInteger(); 12 m = cin.nextBigInteger(); 13 if( (String.valueOf(n)).compareTo(String.valueOf(BigInteger.valueOf(0)))==0 && (String.valueOf(m)).compareTo(String.valueOf(BigInteger.valueOf(0)))==0 ) 14 break; 15 if( (String.valueOf(n)).compareTo(String.valueOf(BigInteger.valueOf(0)))==0||(String.valueOf(m)).compareTo(String.valueOf(BigInteger.valueOf(0)))==0 ){ 16 System.out.println("1"); 17 continue; 18 } 19 if( (String.valueOf(n)).compareTo(String.valueOf(m))<0 ){ 20 tq = n; 21 n = m; 22 m = tq; 23 } 24 BigInteger res; 25 res = BigInteger.valueOf(1); 26 n = n.add( m ); 27 BigInteger i ; 28 i = BigInteger.valueOf(1); 29 //System.out.println( i ); 30 //System.out.println( n ); 31 while( true ){ 32 res = res.multiply(n); 33 res = res.divide(i); 34 n = n.subtract(BigInteger.valueOf(1)); 35 i = i.add(BigInteger.valueOf(1)); 36 if( (String.valueOf(i)).compareTo(String.valueOf(m.add(BigInteger.valueOf(1))))==0 ) break; 37 //System.out.println( res ); 38 } 39 System.out.println( res ); 40 } 41 } 42 } 43 44 45
C(n,m+n)
keep moving...