加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Uncle Jack(大数幂运算java)

发布时间:2020-12-14 03:00:50 所属栏目:大数据 来源:网络整理
导读:Link:http://poj.org/problem?id=3199 Problem: Uncle Jack Time Limit: ?1000MS ? Memory Limit: ?65536K Total Submissions: ?4424 ? Accepted: ?1843 Description Dear Uncle Jack is willing to give away some of his collectable CDs to his nephews

Link:http://poj.org/problem?id=3199

Problem:

Uncle Jack
Time Limit:?1000MS ? Memory Limit:?65536K
Total Submissions:?4424 ? Accepted:?1843

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

Source

Colombia 2006

题意:求将N张相同的CD分给D个人的方法数,即N ^ D。

?

思路:高精度,java的BigInteger有个pow函数。

题意思路转自: http://blog.sina.com.cn/s/blog_6635898a0100ow5e.html
import java.util.*; import java.io.*; import java.math.*; import java.text.*; public class Main{ public static void main(String[] args) { BigInteger x,y; BigInteger ans; Scanner cin=new Scanner(System.in); while(cin.hasNext()) { x=cin.nextBigInteger(); y=cin.nextBigInteger(); if(x.compareTo(BigInteger.valueOf(0))==0&&y.compareTo(BigInteger.ZERO)==0) break; ans=x.pow(y.intValue()); System.out.println(ans); } } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读