Spoj DIVFACT - Divisors of factorial Solution
Problem Link: https://www.spoj.com/problems/DIVFACT/
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <iostream>
using namespace std;
bool isPrime[50001];
#define mod 1000000007
void sieve(long long mx)
{
long long i,j;
for(i=0; i<=mx; i++)
{
isPrime[i]=true;
}
isPrime[0]=isPrime[1]=false;
for(i=2; i*i<=mx; i++)
{
if(isPrime[i]==true)
{
for(j=i*i; j<=mx; j+=i)
isPrime[j]=false;
}
}
}
int main()
{
sieve(50000);
long long int t,i,j,k,n,count=0,r,e,ans;
cin>>t;
while(t--)
{
cin>>n;
i=ans=1;
while(1)
{
if(i>n)break;
if(isPrime[i])
{
r=i;
count=0;
while(int(n/r)>0)
{
count+=int(n/r);
r*=i;
}
ans=(ans*(count+1))%mod;
}
i++;
}
cout<<ans%mod<<endl;
}
}
No comments