This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
int ra,rb,rc,rd;
mod(a,m)
{
return a<0?mod(a+m,m):a%m;
}
f(a1,b1,c1,d1,m)
{
int a2,b2,c2,d2;
for(a2=m-1;a2>=0;a2--)
{
for(b2=m-1;b2>=0;b2--)
{
for(c2=m-1;c2>=0;c2--)
{
for(d2=m-1;d2>=0;d2--)
{
ra=mod(a1*a2-b1*b2-c1*c2-d1*d2,m);
rb=mod(a1*b2+b1*a2+c1*d2-d1*c2,m);
rc=mod(a1*c2-b1*d2+c1*a2+d1*b2,m);
rd=mod(a1*d2+b1*c2-c1*b2+d1*a2,m);
if(ra==1&&rb==0&&rc==0&&rd==0)
{
ra=a2;rb=b2;rc=c2;rd=d2;
return;
}
}
}
}
}
ra=rb=rc=rd=0;
}
main()
{
int m,t;
scanf("%d%d",&m,&t);
for(;t--;)
{
int a1,b1,c1,d1;
scanf("%d%d%d%d",&a1,&b1,&c1,&d1);
f(a1,b1,c1,d1,m);
printf("%d %d %d %d\n",ra,rb,rc,rd);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |