DIVFACT - Divisors of factorial
#include <iostream>
#include <vector>using namespace std;
const int m = 1000000007;
const int N = 50001;
vector<long int> p;
void sieve()
{
bool prime[N] = {false};
for(int i = 3; i * i <= N; i+= 2)
{
if(!prime[i])
{
for(int j = i * i; j <= N; j += i)
{
prime[j] = true;
}
}
}
p.push_back(2);
for(int i = 3; i <= N; i+=2)
{
if(!prime[i])
p.push_back(i);
}
}
long long int findDivisor(int n)
{
long long int result = 1;
int temp = n;
for(long int j = 0; j < p.size() && p[j] <= temp; j++)
{
long long int product = p[j];
long int num = 0;
while(temp / product)
{
num += temp / product;
product *= p[j];
}
if(num)
result = (result * (num + 1)) % m;
}
return result;
}
int main()
{
int t, n;
cin >> t;
sieve();
while(t--)
{
cin >> n;
if(n == 0 || n == 1)
{
cout << 1 << endl;
continue;
}
cout << findDivisor(n) << endl;
}
return 0;
}
Comments
Post a Comment