Mr.BG is very busy person. So you have been given enough time (1000 milliseconds) to help him.

Mr. BG has a bag of marbles with different alphabets written on them. And he has become busy on playing with these marbles by putting them in N boxes placed in a row. There are exactly M distinct type of marbles, N of each type.

Now he puts only N marbles (out of M*N) in N boxes, one by one and upon completion he writes down the letters on the marbles on a paper to form a string. As Mr.BG hates palindrome strings (strings which read same from both sides e.g. MADAM), he erases palindrome string from the paper as soon as he finds one.

Now he is wondering how many different strings he might get on his paper if he could try all possible combination of putting the marbles in the boxes. So you have to help him by answering. As there could be many strings so print it modulo 1,000,000,007.

Input

Input starts with an integer TC(<=10), denoting the number of test cases. Each case starts with two non negative integers N(<=100000) and M(<=26) as described above.

Output

For each case, print the case number and total number of strings written on the paper modulo 1000000007.

Example

Input:

2

2 2

2 3

Output:

Case 1: 2

Case 2: 6

大佬给我们讲的题解,一句带过,我现在还不是很清楚那个公式是怎么来的,先标记下这个题目,m的n方-m的(n+1)/2次方,然后就是大数取余了,wa了一次,因为取余会出现负数,所以要先加上mod

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL po(LL n,LL m){
LL s=m%mod;
for(LL i=1;i<n;i++)
s=(s*m)%mod;
return s;}
int main(){
int t,k=1;
scanf("%d",&t);
while(t--){
LL n,m;
scanf("%lld%lld",&n,&m);
printf("Case %d: %lld\n",k++,(po(n,m)-po((n+1)/2,m)+mod)%mod);
}
return 0;
}

最新文章

  1. 浅析Java 泛型
  2. 2.struts2访问web资源(在struts2中获取session,request等等)
  3. POJ 2226 最小点覆盖(经典建图)
  4. linux下查看系统进程占用的句柄数
  5. SQL数据库增删改查
  6. openstack私有云布署实践【11.2 计算nova - compute节点配置(办公网环境)】
  7. 为XYplorer添加右键菜单:“使用XYplorer打开”
  8. 芝麻HTTP:Python爬虫利器之Xpath语法与lxml库的用法
  9. 导入android SlidingMenu 应用
  10. 题解 AT2390 【Games on DAG】
  11. 语言模型(N-Gram)
  12. vue2.0项目实战(5)vuex快速入门
  13. Http服务基础原理
  14. 我的less学习之路
  15. xargs命令学习
  16. C#应用视频教程3.1 USB工业相机测试
  17. 方法 中 void 的解释
  18. CF1063A Oh Those Palindromes
  19. aps.net session全面介绍(生命周期,超时时间)
  20. KVO 的代码简洁使用

热门文章

  1. github上fork原项目,如何将本地仓库代码更新到最新版本?
  2. lwz程序人生之启程
  3. coredata栈
  4. 设置DataGridView单元格的文本对齐方式
  5. stixel-world跑在kitti数据集
  6. MFC多文档无法显示可停靠窗格
  7. tmpfs与内存盘
  8. Spring中c3p0连接池的配置 及JdbcTemplate的使用 通过XML配置文件注入各种需要对象的操作 来完成数据库添加Add()方法
  9. JavaScript Dom编程艺术(1)
  10. 【转】C++后台开发应该读的书