link of my solution http://www.codechef.com/viewsolution/4337629
getting wrong answer
ans*=j*p[j]; // this can overflow.
You need to take modulo at each intermediate step.
ans*=j*p[j]; // this can overflow.
You need to take modulo at each intermediate step.