I have submitted the solution for the problem MULFACT but it got TLE.Here’s my code :
#include<`bits/stdc++.h`>
using namespace std;
#define MOD 329885391853
#define LL unsigned long long
LL N,i,P,F;
long T;
LL mulMod(LL A,LL B)
{
LL R=0LL;
while(A!=0)
{
if(A&1)
R=(R+B)%MOD;
A>>=1;
B=(B<<1)%MOD;
}
return R;
}
LL Fact[999945]={1LL};
LL Pro[999945]={1LL};
void precalc()
{
Fact[1]=1LL;
Pro[1]=1LL;
for(i=2LL;i<=999982LL;i++)
{
Fact[i]=(Fact[i-1]*i)%MOD;
Pro[i]=mulMod(Pro[i-1],Fact[i]);
}
}
int main()
{
precalc();
scanf("%ld",&T);
while(T--)
{
F=1LL,P=1LL;
scanf("%llu",&N);
if(N>=999983)
printf("0\n");
else
{
printf("%llu\n",Pro[N]);
}
}
return 0;
}
Is there any way to optimise it?