C, 67 bytes
i,n;main(p){for(scanf("%d",&i),n=i;--i;p=p*i*i%n);putchar(48+p%n);}
Prints !1
(a falsey value, by Peter Taylor's definition)0
if (n-1)!^2 == 0 (mod n)
, and 1
otherwise.
EDIT: After some discussion in chat, puts("!1"+p%n)
seems to be considered a bit cheaty, so I've replaced it. The result is one byte longer.
EDIT: Fixed for big inputs.
56 bytes (unary input)Shorter solutions
56 bytes: As recommended in the comments by pawel.boczarski, I could take input in unary by reading the number of command line arguments:
p=1,n;main(i){for(n=--i;--i;p=p*i*i%n);putchar(48+p%n);}
invoking the program like
$ ./a.out 1 1 1 1 1
1 <-- as 5 is prime
51 bytes: If you allow "output" by means of return codes:
p=1,n;main(i){for(n=--i;--i;p=p*i*i%n);return p%n;}