UESTC - 1429 Easy Calculation

 

先给出题目:
                                                                             
Easy Calculation

 

Time Limit: 1000 ms  Memory Limit: 65536 kB
Solved: 27  Tried: 519

 

Description
KO is a Taobao engineer at infrastructure team. He likes thinking, especially about math and algorithm problem. One day a math puzzle comes to his mind.

Let’s define an equation as follow:

f[1][j] = j, j >= 1;
f[i][1] = 1, i >= 1;
f[i][j] = f[i][j-1] * f[i-1][j],  i > 1 and j > 1;

Given two integers n, m, how to calculate the value of f[n][m] mod 10 9?
 

 

Input

The first line of the input is an integer T (T <= 1000), which stands for the number of test cases you need to solve.

Every test case are two integers n, m (1 <= n, m <= 109).

 

 

Output
For every test case, you should output "Case #k: " first, where k indicates the case number and starts at 1. Then the answer f[n][m] mod 10 9. See sample for more details.
 

 

Sample Input
4
1 2
2 2
2 3
3 3
 

 

Sample Output
Case #1: 2
Case #2: 2
Case #3: 6
Case #4: 12
 

 

Source
The 9th UESTC Programming Contest Preliminary
好恶心,竟然注册不了。好吧,于是这个代码就是没交过的了,不过我99%保证这是对的= =(我打过表了)
这题目蛮变态的,这么大的数组,滚动数组也是开不下的。 于是乎就先把一部分的数字打出来看看咯,看看有什么规律。
可以发现10行5列以后,全都是零。前10列(除第一列)就直接用数组存吧。接下来只用找出3列、4列、5列的规律就好了。
为了抓紧时间睡觉,各列的公式以后再打上来吧。  这题最恶心的地方就是5列的时候没法用64位整形表示(应该说我不知道怎么改用它表示,其实我看交的人里面10多个都是用的C++,不过当然考虑他们用了高精度类的情况),非得逼我用java = =。

 

 

 

最后贴上我打出来的表吧。。。发现太大了,算了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值