Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, green or yellow. For some myterious reasons, Panda want both the number of red blocks and green blocks to be even numbers. Under such conditions, Panda wants to know the number of different ways to paint these blocks.

 

Input

The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integerN(1≤N≤10^9) indicating the number of blocks.

 

Output

For each test cases, output the number of ways to paint the blocks in a single line. Since the answer may be quite large, you have to module it by 10007.

 

Sample Input

2
1
2
 

Sample Output

2
6 https://www.bnuoj.com/bnuoj/contest_show.php?cid=8507#problem/101988 一开始打表找规律,无果。
然后分析一下,开始的时候主要怕是2个红,然后绿色的可以4个,6个....这样分类很麻烦。
于是就转换思路。
枚举红色 + 绿色一共有多少个
枚举值就是0、2、4、6.....
我也会想到这样枚举会超时,但是先写公式出来,看看能不能化简,
每一次C(n, k)中,就是红色 + 绿色一共有k个,其中再枚举红色的个数,剩下的就会是绿色的个数了。
C(k, 0) + C(k, 2) + C(k, 4) .... 这个是标准的二项式系数奇次项的和。是2^(k - 1)
然后枚举红色 + 绿色一共有k个后,剩下的n - k个每个有两种选择,2^(n - k),于是一合并,就是2^(n - 1)
提取
2^(n - 1)
然后公式就出来了。

2^n + 2^(n - 1) * (2^(n - 1) - 1)
后面那个减1是因为没有2^0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> int n;
LL ans = ;
int f[];
const int MOD = ;
void dfs(int cur) {
if (cur == n + ) {
int one = , tow = ;
for (int i = ; i <= n; ++i) {
one += f[i] == ;
tow += f[i] == ;
}
if (one % == && tow % == ) ans++;
// ans %= MOD;
return;
}
for (int i = ; i <= ; ++i) {
f[cur] = i;
dfs(cur + );
}
}
int quick_pow(int a, int b) {
int ans = ;
int base = a;
while (b) {
if (b & ) {
ans *= base;
if (ans >= MOD) ans %= MOD;
// ans %= MOD;
}
b >>= ;
base *= base;
if (base >= MOD) base %= MOD;
// base %= MOD;
}
return ans;
}
void work() {
// for (n = 1; n <=14; ++n) {
// ans = 0;
// dfs(1);
//// cout << ans % 10007 << endl;
// printf("n == %d %I64d\n", n, ans);
// }
int n;
scanf("%d", &n);
int ans = (quick_pow(, n) + (quick_pow(, n - ) * ((quick_pow(, n - ) + MOD - ) % MOD)) % MOD ) % MOD;
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
cin >> t;
while (t--) work();
return ;
}


最新文章

  1. webhdfs 使用shell下载文件
  2. mysql CREATE USER
  3. Python爬虫学习(2): httplib
  4. updatepanel 回发或回调参数无效
  5. Ninject之旅之五:Ninject XML配置
  6. 【Xcelsius】在PPT中嵌入水晶易表Xcelsius2008仪表盘
  7. 使用Android Studio开发J2SE项目方法
  8. 【全面完美方案】iPhone 4S WiFi变灰 DIY修复方式
  9. 各加密模式的演示(ECB,CBC)
  10. android术语笔记
  11. Cppcheck 1.54 C/C++静态代码分析工具
  12. 2014最热门、最具争议的10个Java话题
  13. 实践作业1:测试管理工具实践 Day3
  14. android 获取屏幕的宽和高
  15. SDN第三次上机作业
  16. 【Python】 xml解析与生成 xml
  17. ●BZOJ 1853 [Scoi2010]幸运数字
  18. linux ----&gt; centos 网络、tomcat、vi、等等的配置和使用
  19. C语言预处理命令详解
  20. 如何在SQL Server查询语句(Select)中检索存储过程(Store Procedure)的结果集?

热门文章

  1. 用rem适配移动端
  2. nginx rewrite 导致验证码不正确
  3. Linux Shell: 统计系统中占用Swap 的程序PID和占用大小
  4. BZOJ - 2553 :禁忌(AC自动机+贪心+奇怪的矩阵)
  5. 「LuoguP2365」 任务安排(dp
  6. 1066 Bash 游戏
  7. Father Christmas flymouse
  8. DataGrid当列宽超出当前宽度时,没有数据也恒有滚动条
  9. Redis实现求交集操作结果缓存的设计方案
  10. C#Dos命令