Problem Link
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define LL long long
#define sf(i) scanf("%d", &i)
#define sl(i) scanf("%ld", &i)
const LL N = 5000000;
const LL MOD = 1000000007;
bool isPrime[N + 1];
LL prime[N + 1];
LL dp[N + 1];
void sieve()
{
memset(isPrime, true, sizeof isPrime);
for(LL i = 2; i * i <= N; i++)
{
if(isPrime[i])
{
for(LL j = i * i; j <= N; j += i)
{
isPrime[j] = false;
}
}
}
isPrime[1] = false;
prime[0] = 0;
for(LL i = 1; i <= N; i++)
{
prime[i] = (prime[i-1] + (isPrime[i] ? 1 : 0));
}
}
void init()
{
dp[1] = 1LL;
for(LL i = 2; i <= N; i++)
{
dp[i] = ((dp[i - 1] % MOD) * (1 + prime[i])) % MOD;
}
}
int main()
{
int t;
LL n;
sieve();
init();
sf(t);
while(t--)
{
sl(n);
printf("%lld\n", dp[n]);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define LL long long
#define sf(i) scanf("%d", &i)
#define sl(i) scanf("%ld", &i)
const LL N = 5000000;
const LL MOD = 1000000007;
bool isPrime[N + 1];
LL prime[N + 1];
LL dp[N + 1];
void sieve()
{
memset(isPrime, true, sizeof isPrime);
for(LL i = 2; i * i <= N; i++)
{
if(isPrime[i])
{
for(LL j = i * i; j <= N; j += i)
{
isPrime[j] = false;
}
}
}
isPrime[1] = false;
prime[0] = 0;
for(LL i = 1; i <= N; i++)
{
prime[i] = (prime[i-1] + (isPrime[i] ? 1 : 0));
}
}
void init()
{
dp[1] = 1LL;
for(LL i = 2; i <= N; i++)
{
dp[i] = ((dp[i - 1] % MOD) * (1 + prime[i])) % MOD;
}
}
int main()
{
int t;
LL n;
sieve();
init();
sf(t);
while(t--)
{
sl(n);
printf("%lld\n", dp[n]);
}
return 0;
}
Comments
Post a Comment