Teemo has a formula and he want to calculate it quickly.
As the result may be very large, please output the result mod 1000000007.
Input Format
The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 10^5.
For each test case, the first line contains an integer n(1<=n<=10^9).
Output Format
For each test case, output a line containing an integer that indicates the answer.
样例输入
2 2 3
样例输出
6 24
解题思路:
a(n) = n*(n+1)*2^(n-2) |
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 //必须宏定义,传参会超时
typedef long long ll;
ll ModMul(ll a,ll b)//快速积取模 a*b%n
{
ll ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return ans;
}
ll ModExp(ll a,ll b)//快速幂取模 a^b%n
{
ll ans=1;
while(b)
{
if(b&1)
ans=ModMul(ans,a);
a=ModMul(a,a);
b>>=1;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
if(n==1)
printf("%lld\n",1);
else
printf("%lld\n",ModMul(ModMul(n,n+1),ModExp(2,n-2)));
}
return 0;
}