Skip to main content
3 of 6
added 173 characters in body
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#C, trial division, 75 bytes#

i=1; main(n){for(scanf("%d",&n);n%i++&&i<n;);printf("%d",n<3?n-1:n%i);} 

Note special handling for n=1,2

Also, here's the version that takes n at the commandline, at 81 bytes.

i=1; main(int n,char**v){for(n=atoi(v[1]);n%i++&&i<n;);printf("%d",n<3?n-1:n%i);} 
Level River St
  • 28.8k
  • 4
  • 40
  • 112