POJ - 3734 Blocks 指数型生成函数

code: 

#include <cstdio> 
#include <algorithm>   
#define mod 10007 
#define ll long long 
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std;   
int qpow(int x,int y) 
{
    int tmp=1;  
    for(;y;y>>=1,x=(ll)x*x%mod) 
        if(y&1) tmp=(ll)tmp*x%mod;  
    return tmp; 
}   
int INV(int x) { return qpow(x,mod-2); }  
int main() 
{ 
    // setIO("input");  
    int i,j,T,inv4=INV(4);  
    scanf("%d",&T); 
    while(T--) 
    {
        int n; 
        scanf("%d",&n);         
        printf("%d\n",(ll)inv4*(ll)(qpow(4,n)+qpow(2,n+1))%mod);  
    }   
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/guangheli/p/12192145.html