Skip to main content
Commonmark migration
Source Link

#C, trial division, 72 bytes#

C, trial division, 72 bytes

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

#C, trial division, 72 bytes#

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

C, trial division, 72 bytes

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

deleted 6 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#C, trial division, 7372 bytes#

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

#C, trial division, 73 bytes#

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

#C, trial division, 72 bytes#

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

deleted 60 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#C, trial division, 7573 bytes#

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

Note special handling for n=1,2

Also, here'sWe need to stop the version that takesloop before i gets to n at the commandline-1, at 81 bytesso i<n-1 would do, but i*i<n is more efficient.

i=1; main(int n,char**v){for(n=atoi(v[1]);n%i++&&i<n;);printf("%d",n<3?n-1:n%i);} 

#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);} 

#C, trial division, 73 bytes#

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

Note special handling for n=1,2

We need to stop the loop before i gets to n-1, so i<n-1 would do, but i*i<n is more efficient.

added 173 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading
added 9 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading