#include<stdio.h>
int main()
{
int t,n,x,i;
scanf("%d",&t);
while(t--)
{
int sum=0,prod=1;
scanf("%d%d",&n,&x);
for(i=1;i<=n;i++)
{
prod=prod*(i%x);
}
printf("%d\n",prod%x);
}
return 0;
}Asked by: bandaram_Sumanth on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
See this link, http://recursionnitd.in/askrec/questions/14, i have answered similar question, you might get some help there.