POJ 3199 Uncle Jack(JAVA练习)

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();
      }
    }
}

时间: 2024-11-02 14:58:33

POJ 3199 Uncle Jack(JAVA练习)的相关文章

POJ Exponentiation(大浮点数JAVA轻松解决)

题目链接:Clicke Here~ java解决大数就是爽阿!~ 以前大数模板敲啊敲的,敲了半天发现一交果断wrong.只从学会了java妈妈在不用担心我遇到大数了/ 这道题遇到的Java函数有: stripTrailingZeros()            去掉后缀0 toPlainString()               返回大数的非科学计数法 startsWith() startsWith()函数介绍及扩展: 描述 startsWith(),endsWith()的作用,用法,判断字符

POJ 1001 Exponentiation(JAVA,BigDecimal->String)

题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); BigDecimal a = BigDecimal.ONE; BigDecimal ans = BigDecimal.ONE; int n; while(in.hasNextBi

POJ 1131 Octal Fractions (Java大数,八进制转十进制)

Octal Fractions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6959   Accepted: 3825 Description Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.953125 (7/8 + 5/64) in d

算法之路——POJ刷题(Java,持续更新中)

先拿一些水题来练手了 1.POJ1000 import java.util.Scanner; /** * Created by mxcsky on 2015/1/25. */ public class POJ1000 { public static void main(String[] args){ Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); System.out.println

poj 2305 Basic remains java

import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin= new Scanner(System.in); int b=0; while(cin.hasNextInt())

POJ 2305 Basic remains(JAVA练习)

Description Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a. Input Input consist

POJ题目Java代码(一)

POJ 1001 Exponentiation import java.math.BigDecimal; import java.util.Scanner; public class Poj1001 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ BigDecimal bigDecimal = new BigDecimal(sc.next())

Java 包(package)

为了更好地组织类,Java 提供了包机制,用于区别类名的命名空间. 包的作用 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹一样,包也采用了树形目录的存储方式.同一个包中的类名字是不同的,不同的包中的类的名字是可以相同的,当同时调用两个不同包中相同类名的类时,应该加上包名加以区别.因此,包可以避免名字冲突. 3.包也限定了访问权限,拥有包访问权限的类才能访问某个包中的类. Java 使用包(package)这种机制是为了防止命名冲突,访问控制,提供搜索和定位

【Java编程】JDBC注入攻击-Statement 与 PreparedStatement

在上一篇[Java编程]建立一个简单的JDBC连接-Drivers, Connection, Statement and PreparedStatement我们介绍了如何使用JDBC驱动建立一个简单的连接,并实现使用Statement和PreparedStatement进行数据库查询,本篇blog将接着上篇blog通过SQL注入攻击比较Statement和PreparedStatement.当然这两者还有很多其他方面的不同,在之后的blog中会继续更新. [Statement查询] 1.在DBH