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

Mutual Training for Wannafly Union #8 D - Mr.BG Hates Palindrome 取余的更多相关文章

  1. 【Mutual Training for Wannafly Union #1 】

    A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...

  2. Mutual Training for Wannafly Union #1解题报告

    ---恢复内容开始--- q神等人组织的vjudge上的多校训练,题目基本上都来自于CF,#1是上周进行的,参加后感觉收获很多,因为上周准备期中比较忙,解题报告现在补上. 比赛地址(兼题目地址) A题 ...

  3. Mutual Training for Wannafly Union #6 E - Summer Trip(并查集)

    题目链接:http://www.spoj.com/problems/IAPCR2F/en/ 题目大意: 给m个数字代表的大小,之后n组数据,两两关联,关联后的所有数字为一组,从小到大输出组数以及对应的 ...

  4. Mutual Training for Wannafly Union #2

    codeforces 298A. Snow Footprints 分类讨论三种情况: ①..RRRRRR…  ②..LLLLLLL… ③..RRRLLLL.. //AC by lwq: #includ ...

  5. Mutual Training for Wannafly Union #9

    A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成 ...

  6. Mutual Training for Wannafly Union #6

    A =w= B QvQ C 题意:有长度为n的序列(n<=5e5),求满足条件的a,b,c,d的组数,要求满足条件:min([a,b])<=min([c,d]),a<=b<c& ...

  7. Mutual Training for Wannafly Union #5

    A(UVA12336) 题意:给一个n*m(n,m<=1e5)的棋盘,棋盘上有一些障碍点不能放棋子,现在要在棋盘上放4个棋子,满足A->B->C->D->A,其中走的规则 ...

  8. Wannafly Union Goodbye 2016

    A 题意:平面上有n个点(n<=100000),给你一个p(20<=p<=100) 判断是否存在一条直线至少过[np/100](向上取整)个点,时限20s,多组数据 分析:概率算法 ...

  9. Wannafly Union#1

    题目链接:http://vjudge.net/contest/142053#overview A.题意:有一个3*n的隧道,人和车轮流走,人先向右走一步,然后选在是在原地不动还是上下移动一格,之后车开 ...

随机推荐

  1. TCP/IP协议分析含义与功能

    TCP/IP协议模型从更实用的角度出发,形成了高效的四层体系结构,即网络接口层.IP层.传输层和应用层.TCP/IP是一组专业化协议,包括IP.TCP.UDP.ARP.ICMP以及其它的一些被称为子协 ...

  2. python中的构造函数和构造函数和析构函数的作用

    构造函数和构造函数和析构函数都属于python中的特殊方法 其中的“__del__”就是一个析构函数了,当使用del 删除对象时,会调用他本身的析构函数,另外当对象在某个作用域中调用完毕,在跳出其作用 ...

  3. 洛谷 P1145 约瑟夫

    题目描述 n个人站成一圈,从某个人开始数数,每次数到m的人就被杀掉,然后下一个人重新开始数,直到最后只剩一个人.现在有一圈人,k个好人站在一起,k个坏人站在一起.从第一个好人开始数数.你要确定一个最小 ...

  4. 【Python图像特征的音乐序列生成】使用Python生成简单的MIDI文件

    这个全新的Python音乐创作系列,将会不定期更新.写作这个系列的初衷,是为了做一个项目<基于图像特征的音乐序列生成模型>,实时地提取照片特征,进行神经网络处理,生成一段音乐. 千里之行, ...

  5. BZOJ 3232: 圈地游戏 分数规划+判负环

    3232: 圈地游戏 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 966  Solved: 466[Submit][Status][Discuss] ...

  6. codeforces Gym 100286H Hell on the Markets

    紫书上面的题,队友做的,WA了freopen..爆了int... UVA 1614 - Hell on the Markets 奇怪的股市(贪心,结论)

  7. ArrayList 源码分析(JDK1.8)

    ArrayList简介  ArrayList 是一个数组队列,相当于 动态数组.与Java中的数组相比,它的容量能动态增长.它继承于AbstractList,实现了List, RandomAccess ...

  8. groupadd - 建 立 新 群 组

    总览 SYNOPSIS groupadd [-g gid [-o]] [-r] [-f] group 描述 DESCRIPTION groupadd 可 指 定 群 组 名 称 来 建 立 新 的 群 ...

  9. 摘自 dd大牛的《背包九讲》

    P01: 01背包问题 题目 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 基本思路 这是最 ...

  10. 使用Electron开发PC客户端

    最近公司要求开发一个PC客户端,要求不能使用.NET开发(为了不让用户安装.net framework),所以就选择了Electron(随口听别人说了一句,之前从来没有接触过).目前项目要完毕了,所以 ...