Source Code
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pb push_back
#define pp pop_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
ld pi=acos(-1);
ll mod=1e9+7;
void fast()
{
	cin.sync_with_stdio(0) ;
		cin.tie(0) ;
		cout.tie(0);
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
	if(a.first==b.first)
		return b.second>a.second;
	return a.first<b.first;
}
long long gcd(long long a,long long b)
{
	if(a==0)
		return b;
	return gcd(b%a,a);
}
long long fp(ll b, ll p)
{
    ll ans = 1;
    while (p)
    {
        if (p % 2)
        {
            ans = (ans * b)%mod;
        }
        b = (b * b)%mod;
        p /= 2;
    }
    return ans%mod;

}
bool isp(long long n)
{
	if(n==1)
		return false;
	if(n==2||n==3)
		return true;
	if(n%2==0||n%3==0)
		return false;
	for(long long i=5;i*i<=n;i+=2)
		if(n%i==0)
			return false;
	return true;
}
long long fc(long long n)
{
	if(n==0)
		return 1;
	long long s=1;
	for(int i=1;i<=n;i++)
		s=s*i;
	return s;
}
ll lcm(ll a,ll b)
{
	ll m=gcd(a,b);
	m=a/m*b;
	return m;
}
#define MAX 10000001
ll primes[MAX] ;
bool sieve[MAX] ;
int l;
void genPrimes()
{
    primes[l++] = 2 ;
    long long i,j ;
    for(j=4;j<MAX;j+=2)               sieve[j] = true ;
    for(i=3;i<MAX;i+=2)
    {
        if(sieve[i]==false)
        {
            primes[l++] = i ;
            for(j=i*i;j<MAX;j+=i)   sieve[j] = true ;
        }
    }
}
void Nn(ll n)
{
	map<int,int>mp;
	int od=0,ev=0;
    ll tmp = sqrt(n),i ;
    ll j = 0 ;
    ll p[1000];
    memset(p,0,sizeof(p));
    for(i=0;primes[i]<=tmp;i++)
        if(n % primes[i] == 0)
        {
            int cnt =  0 ;
            while(n % primes[i] == 0)
            {
                cnt ++ ;
                //cout<<"    "<<primes[i]<<"\n";
                n /=primes[i] ;
            }
            if(cnt%2)
            	od++;
            else
            	ev++;
            p[j++]=primes[i] ;
            mp[primes[i]]=cnt;
            tmp = sqrt(n) ;
        }
    if(n>1) {
    	p[j++]=n;
    	od++;
    //	cout<<"    "<<n<<"\n";
    	mp[n]++;
    }
    sort(p,p+j);
    for(int i=0;i<j;i++)
    	cout<<p[i]<<'^'<<mp[p[i]]<<" ";
   // sort(p,p+j);

}
/*ll c=1e9+7;
ll modd(ll a,ll b)
{
	ll rs=0;
	a=a%c;
	while(b)
	{
		if(b%2)
			rs=(rs+a)%c;
		a=(2*a)%c;
		b/=2;
	}
	return rs;
}*/
const int N = 1000001;
ll factorialNumInverse[N + 1];
ll naturalNumInverse[N + 1];
ll fact[N + 1];
 void InverseofNumber(ll p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (int i = 2; i <= N; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(ll p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (int i = 2; i <= N; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
 void factorial(ll p)
{
    fact[0] = 1;
     for (int i = 1; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
 ll B(ll N, ll R, ll p)
{
    ll ans = ((fact[N] * factorialNumInverse[R])
              % p * factorialNumInverse[N - R])% p;
    return ans;
}
int main() {
    fast();
    ll p = 1000000007;
    InverseofNumber(p);
    InverseofFactorial(p);
    factorial(p);
	int tt=1;
	cin>>tt;
	for(int ts=1;ts<=tt;ts++)
	{
		ll n;
		cin>>n;
		ll s=0,m=2;
		for(ll i=0;i<=n/2;i++)
		{
			s=(s+B(n-i,i,p))%p;
		}
		cout<<s<<"\n";
	}
	return 0;
}
Copy
Study Schedule sameh58
GNU G++17
2080 ms
24.2 MB
Time Limit Exceeded