Skip to main content
added 235 characters in body
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70

C (gcc), 43 bytes

f(n,i){for(i=1;n%++i;);n=i<n&&f(n/i)^i?:i;} 

Try it online!

Returns p if n is almost-prime, and 1 otherwise.

f(n,i){ for(i=1;n%++i;); // identify i = the least prime factor of n n=i<n&&f(n/i)^i // if n is neither prime nor almost-prime ? // return 1 :i; // return i } 

C (gcc), 43 bytes

f(n,i){for(i=1;n%++i;);n=i<n&&f(n/i)^i?:i;} 

Try it online!

Returns p if n is almost-prime, and 1 otherwise.

C (gcc), 43 bytes

f(n,i){for(i=1;n%++i;);n=i<n&&f(n/i)^i?:i;} 

Try it online!

Returns p if n is almost-prime, and 1 otherwise.

f(n,i){ for(i=1;n%++i;); // identify i = the least prime factor of n n=i<n&&f(n/i)^i // if n is neither prime nor almost-prime ? // return 1 :i; // return i } 
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70

C (gcc), 43 bytes

f(n,i){for(i=1;n%++i;);n=i<n&&f(n/i)^i?:i;} 

Try it online!

Returns p if n is almost-prime, and 1 otherwise.