码迷,mamicode.com
首页 > 编程语言 > 详细

POJ 3199 Uncle Jack(JAVA练习)

时间:2014-08-25 15:04:04      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   java   os   io   ar   div   cti   

Description

Dear Uncle Jack is willing to give away some of his collectable CDs to his nephews. Among the titles you can find very rare albums of Hard Rock, Classical Music, Reggae and much more; each title is considered to be unique. Last week he was listening to one of his favorite songs, Nobody’s fool, and realized that it would be prudent to be aware of the many ways he can give away the CDs among some of his nephews.

So far he has not made up his mind about the total amount of CDs and the number of nephews. Indeed, a given nephew may receive no CDs at all.

Please help dear Uncle Jack, given the total number of CDs and the number of nephews, to calculate the number of different ways to distribute the CDs among the nephews.

Input

The input consists of several test cases. Each test case is given in a single line of the input by, space separated, integers N (1 ≤ N ≤ 10) and D (0 ≤ D ≤ 25), corresponding to the number of nephews and the number of CDs respectively. The end of the test cases is indicated with N = D = 0.

Output

The output consists of several lines, one per test case, following the order given by the input. Each line has the number of all possible ways to distribute D CDs among N nephews.

Sample Input

1 20
3 10
0 0

Sample Output

1
59049
求n^d。。大数,JAVA,对c++大数模板真是无爱,果断JAVA。
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] arges){
    	BigInteger n;
    	int d;
        Scanner cin = new Scanner (System.in);
        while(cin.hasNext()){
        n=cin.nextBigInteger();
        d=cin.nextInt();
        if(n.compareTo(BigInteger.ZERO)==0&&d==0)  break;
        	
        BigInteger ans;
        ans=n.pow(d);
        System.out.println(ans);
//        System.out.println();
      }
    }
}


POJ 3199 Uncle Jack(JAVA练习)

标签:des   style   color   java   os   io   ar   div   cti   

原文地址:http://blog.csdn.net/u013582254/article/details/38819807

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!