1417: 2048


Time Limit: 1 Sec  Memory Limit: 128 MB

[​​Submit​​​][​​Status​​​][​​Web Board​​]

Description


想必大家都玩过2048的游戏,小明想知道这个游戏能出现的最高数字是多少?请你帮忙计算,当然小明玩的2048和我们的不太一样,小明的2048不一定是4X4的格子,可以使3X2等等。小明的2048只能随机生成2。


Input


输入n,m(0<=n,m<=10^4)表示有2048游戏矩阵的大小,当0,0时结束;


Output


输出理论最大值,答案对1000000007取余。


Sample Input

2 20 0

Sample Output

16


【分析】


因为只能生成2,所以最终的最优情况就是按2的次方放满的时候...举个例子就知道了


比如3*2的最终情况是

64  32  16

8 2 1


自己测几个例子算算看就知道了...虽然说是一个矩阵,其实可以看成一条直线....


所以就是求2^(n*m)%1000000007


n*m比较大所以快速幂就好了~


这是我第一次用C语言写快速幂...也是第一次知道C语言位运算里的左移和右移...


【代码】

#include <stdio.h>
#include <math.h>
#define MOD 1000000007
long long find(int n)
{
long long a=2;
long long ans=1;
while (n)
{
if (n&1) ans=ans*a%MOD;
a=a*a%MOD;
n>>=1;
}
return ans;
}


int main()
{
int n,m;
while (~scanf("%d%d",&n,&m) &&(n!=0 || m!=0))
if (n==0||m==0) printf("0\n");
else
{
n*=m;
printf("%lld\n",find(n));
}
}