Untitled
unknown
c_cpp
a year ago
1.9 kB
8
Indexable
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void FIO() {
#ifndef ONLINE_JUDGE
freopen("../in.txt", "r", stdin);
freopen("../out.txt", "w", stdout);
#endif
}
const int N = 1e6 + 50;
bool isPrime[N];
vector<int> primes;
const int M = 1e9 + 7;
int add(int a, int b) {
return (a + b) % M;
}
int mul(int a, int b) {
return (1LL * a * b) % M;
}
int power(int x, ll p) {
int res = 1;
while (p) {
if (p & 1) {
res = mul(res, x);
}
x = mul(x, x);
p >>= 1;
}
return res;
}
int fact[N], invFact[N];
bool composite[N];
vector<int> prime;
void pre() {
fact[0] = 1;
for (int i = 1; i < N; ++i) {
fact[i] = (1LL * fact[i - 1] * i) % M;
}
invFact[N - 1] = power(fact[N - 1], M - 2);
for (int i = N - 2; i >= 0; --i) {
invFact[i] = (1LL * invFact[i + 1] * (i + 1)) % M;
}
memset(isPrime, true, sizeof(isPrime));
isPrime[0] = isPrime[1] = false;
composite[0] = composite[1] = true;
for (int i = 2; i < N; ++i) {
if (!composite[i])
prime.push_back(i);
for (int j = 0; j < prime.size() && i * prime[j] < N; ++j) {
composite[i * prime[j]] = true;
if (i % prime[j] == 0)
break;
}
}
}
int nCr(int n, int r) {
if (r > n) {
return 0;
}
int res = fact[n];
res = mul(res, invFact[r]);
res = mul(res, invFact[n - r]);
return res;
}
void solve() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (!composite[i]) {
ans = add(ans, nCr(n, i));
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
FIO();
pre();
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}Editor is loading...
Leave a Comment