[Question]
  [
A Sphenic Number is a number that is the product of exactly three distinct primes. The first few Sphenic numbers are `30, 42, 66, 70, 78, 102, 105, 110, 114`. This is sequence [A007304](https://oeis.org/A007304) in the OEIS. 
## Your Task:
Write a program or function to determine whether an inputted integer is a Sphenic number. 
## Input:
An integer between 0 and 10^9, which may or may not be a Sphenic Number. 
## Output:
A truthy/falsy value indicating whether the input is a Sphenic Number. 
## Examples:
```
30  -> true
121 -> false
231 -> true
154 -> true
4   -> false
402 -> true
79  -> false
0   -> false
60  -> false
64  -> false
8   -> false
210 -> false
```
## Scoring:
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest code in bytes wins. 
  
[Answer]
## bash, 43 bytes
```
factor $1|awk '{print $2-$3&&$3-$4&&NF==4}'
```
[Try it online!](https://tio.run/##HY5NCsIwGET3PcVQPpJVoPlREdouXXqHNDa0qInUiAXr2WNwZlaPt5jBPqfsbELb8pWj99lbl@ICkpt9X8E/j2UOCaQEacZICzKMnU9dZ748r5UvasAcoBtIJaG0hNwZlDYKhyMa7MtMdYkVSkY3RYiAmgJEj/oPh3ICHhSKFUZscPH2uhch5R8 "Bash – Try It Online")
Input via command line argument, outputs `0` or `1` to stdout.
Fairly self-explanatory; parses the output of `factor` to check that the first and second factors are different, the second and third are different (they're in sorted order, so this is sufficient), and there are four fields (the input number and the three factors).
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
_YF7BX=
```
[Try it online!](https://tio.run/##y00syfn/Pz7Szdwpwvb/f0MDUwA "MATL – Try It Online") Or [verify all test cases](https://tio.run/##y00syfmf8D8@0s3cKcL2v0vIf2MDLkMjQy4jY0MuQ1MTLiA0MOIyt@Qy4DIDIhMA).
### Explanation
```
_YF   % Implicit input. Nonzero exponents of prime-factor decomposition
7     % Push 7
B     % Convert to binary: gives [1 1 1] 
X=    % Is equal? Implicit display
```
[Answer]
# C, ~~88~~ ~~78~~ ~~126~~ ~~58~~ ~~77~~ 73 + 4 (`lm`) = 77 bytes
```
l,j;a(i){for(l=1,j=0;l++<i;fmod(1.*i/l,l)?i%l?:(i/=l,j++):(j=9));l=i==1&&j==3;}
```
Ungolfed commented explanation:
```
look, div; //K&R style variable declaration. Useful. Mmm.
a ( num ) { // K&R style function and argument definitions.
  for (
    look = 1, div = 0; // initiate the loop variables.
    look++ < num;) // do this for every number less than the argument:
      if (fmod(1.0 * num / look, look))
      // if num/look can't be divided by look:
        if( !(num % look) ) // if num can divide look
          num /= look, div++; // divide num by look, increment dividers
      else div = 9;
      // if num/look can still divide look
      // then the number's dividers aren't unique.
      // increment dividers number by a lot to return false.
  // l=j==3;
  // if the function has no return statement, most CPUs return the value
  // in the register that holds the last assignment. This is equivalent to this:
  return (div == 3);
  // this function return true if the unique divider count is 3
}
```
[Try it online!](https://tio.run/##JcxBDoIwEADAr5gmJLu2COjJLg0f8dIslLRZwACejF@3kviAGS5H5pzFJPIQ8R2WFcQ1JrmaROs2UpiWHprLOVZiBLtYSGchVu4gWqOF5O6IJC45d6NPZpp8nOE/EbfXuiZ8rnHeA6ji1ttTsT1mZVhr44GxU/v6GpRVwcs2KDyKLwfx45ZLmX4 "C (gcc) – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~6~~ 3 bytes
```
ḋ≠Ṫ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@GO7kedCx7uXPX/v5Gx4X8A "Brachylog – Try It Online")
### Explanation
```
ḋ        The prime factorization of the Input…
 ≠       …is a list of distinct elements…
  Ṫ      …and there are 3 elements
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 11 bytes
```
rimFz1=7Yb=
```
[Try it online!](https://tio.run/##S85KzP3/vygz163K0NY8Msn2/39DA1MA "CJam – Try It Online") Or [verify all test cases](https://tio.run/##S85KzP1f/T8nM9etytDWPDLJ9n@BYW36f2MDLkMjQy4jY0MuQ1MTLiA0MOIyt@Qy4DIDIhMA).
### Explanation
Based on my MATL answer.
```
ri    e# Read integer
mF    e# Factorization with exponents. Gives a list of [factor exponent] lists
z     e# Zip into a list of factors and a list of exponents
1=    e# Get second element: list of exponents
7     e# Push 7
Yb    e# Convert to binary: gives list [1 1 1]
=     e# Are the two lists equal? Implicitly display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ÆEḟ0⁼7B¤
```
[Try it online!](https://tio.run/##y0rNyan8//9wm@vDHfMNHjXuMXc6tOT////GBgA "Jelly – Try It Online")
Uses Luis Mendo's algorithm.
Explanation:
```
ÆEḟ0⁼7B¤
ÆE       Prime factor exponents
  ḟ0     Remove every 0
    ⁼7B¤ Equal to 7 in base 2?
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ÆE²S=3
```
[Try it online!](https://tio.run/##y0rNyan8//9wm@uhTcG2xv@P7jnc/qhpjfv//8YGOgqGRoY6CkbGQMLQ1ERHAYQMjHQUzC11FICyZiBsAgA "Jelly – Try It Online")
### How it works
```
ÆE²S=3  Main link. Argument: n
ÆE      Compute the exponents of n's prime factorization.
  ²     Take their squares.
   S    Take the sum.
    =3  Test the result for equality with 3.
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 6 bytes
```
≡ḋ3Ẋ≠p
```
[Try it online!](https://tio.run/##yygtzv7//1Hnwoc7uo0f7up61Lmg4P///8YGAA "Husk – Try It Online")
Returns 1 for sphenic numbers and 0 otherwise.
### Explanation
```
≡ḋ3Ẋ≠p    Example input: 30
     p    Prime factors: [2,3,5]
   Ẋ≠     List of absolute differences: [1,2]
≡         Is it congruent to...       ?
 ḋ3           the binary digits of 3: [1,1]
```
In the last passage, congruence between two lists means having the same length and the same distribution of truthy/falsy values. In this case we are checking that our result is composed by two truthy (i.e. non-zero) values.
[Answer]
# Ruby, ~~81~~ ~~49~~ 46 bytes
Includes 6 bytes for command line options `-rprime`.
```
->n{n.prime_division.map(&:last)==[1]*3}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOk@voCgzNzU@JbMsszgzP08vN7FAQ80qJ7G4RNPWNtowVsu49n@BQlq0kWWsDpAyNoBQhmDKBEoZxf7/l19QAtRf/F@3CGwiAA "Ruby – Try It Online")
[Answer]
# Mathematica, 31 bytes
```
SquareFreeQ@#&&PrimeOmega@#==3&
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~7~~ 5 bytes
```
ÓnO3Q
```
[Try it online!](https://tio.run/##MzBNTDJM/f//8OQ8f@PA//@NDQA "05AB1E – Try It Online")
Uses Dennis's algorithm.
[Answer]
# Pyth, 9 bytes
```
&{IPQq3lP
```
[Try it here.](http://pyth.herokuapp.com/?code=%26%7BIPQq3lP&input=30&debug=0)
[Answer]
# [Actually](https://github.com/Mego/Seriously), 7 bytes
```
w♂N13α=
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/7/80cwmP0Pjcxtt//83NgAA "Actually – Try It Online")
Explanation:
```
w♂N13α=
w       Push [prime, exponent] factor pairs
 ♂N     Map "take last element"
   1    Push 1
    3   Push 3
     α  Repeat
      = Equal?
```
[Answer]
# [Haskell](https://www.haskell.org/), 59 bytes
```
f x=7==sum[6*0^(mod(div x a)a+mod x a)+0^mod x a|a<-[2..x]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwtbc1ra4NDfaTMsgTiM3P0UjJbNMoUIhUTNRG8gDs7QN4qDMmkQb3WgjPb2K2Nj/uYmZebYFRZl5JSppCiYGRv8B "Haskell – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
k
k@è¥X ÉÃl ¥3
```
[Try it online!](https://codepen.io/justinm53/full/NvKjZr?code=awprQOilWCDJw2wgpTM=&inputs=MzA=,MTIx,MjMx,MTU0,NA==,NDAy,Nzk=,MA==,NjA=,NjQ=)
[Answer]
# [J](http://jsoftware.com/), 15 bytes
```
7&(=2#.~:@q:)~*
```
[Try it online!](https://tio.run/##y/r/P03B1krBXE3D1khZr87KodBKs06Liys1OSNfQUNHL03JQFPB2EDB0MhQwcjYUMHQ1EQBCA2MFMwtFQwUzIDI5P9/AA "J – Try It Online")
## Explanation
```
7&(=2#.~:@q:)~*  Input: integer n
              *  Sign(n)
7&(         )~   Execute this Sign(n) times on n
                 If Sign(n) = 0, this returns 0
          q:       Prime factors of n
       ~:@         Nub sieve of prime factors
    2#.            Convert from base 2
   =               Test if equal to 7
```
[Answer]
# Dyalog APL, 26 bytes
```
⎕CY'dfns'
((≢,∪)≡3,⊢)3pco⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKPdOSM1Ofv/o76pzpHqKWl5xepcGhqPOhfpPOpYpfmoc6GxzqOuRZrGBcn5QCUg9f/BGriMDbi4ICxDI0MY08gYzjQ0NYExEQwDIxjT3BLGMoMbZGYCAA)
[Answer]
# Mathematica, 44 bytes
```
Plus@@Last/@#==Length@#==3&@FactorInteger@#&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvs/IKe02MHBJ7G4RN9B2dbWJzUvvSQDxDJWc3BLTC7JL/LMK0lNTy1yUFb7H1CUmQdUl6bvUG1soKNgaGSoo2BkDCQMTU10FEDIwEhHwdxSRwEoawbCJrX/AQ "Mathics – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~54~~ 53 bytes
```
lambda n:sum(1>>n%k|7>>k*k%n*3for k in range(2,n))==6
```
*Thanks to @xnor for golfing off 1 byte!*
[Try it online!](https://tio.run/##FYxBCoMwFETX7SlmE4zyCyaxSoXkJN1YWluJfiXqotC7pwbmzeINzPLdPjOb2MPiHsduejw7cLvuk1TOsfC/xjlfeMGF6ecAj4EROn6/pCbOc2vrmDwnb0qC0oqgzVHqWhFSSk1oboRjrRNVez4tYeBNZsLsuDiINYOAZEIvj9M8/gE "Python 3 – Try It Online")
[Answer]
**C, 91 102 bytes, corrected (again), golfed, and tested for real this time:**
```
<strike>s(c){p,f,d;for(p=2,f=d=0;p<c&&!d;){if(c%p==0){c/=p;++f;if(c%p==0)d=1;}++p;}c==p&&f==2&&!d;}</strike>
s(c){int p,f,d;for(p=2,f=d=0;p<c&&!d;){if(c%p==0){c/=p;++f;if(c%p==0)d=1;}++p;}return c==p&&f==2&&!d;}
```
/\* This also works in 93 bytes, but since I forgot about the standard rules barring default int type on dynamic variables, and about the not allowing implicit return values without assignments, I'm not going to take it:
```
p,f,d;s(c){for(p=2,f=d=0;p<c&&!d;){if(c%p==0){c/=p;++f;if(c%p==0)d=1;}++p;}p=c==p&&f==2&&!d;}
```
(Who said I knew anything about C? ;-)
Here's the test frame with shell script in comments:
```
/* betseg's program for sphenic numbers from 
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h> /* compile with -lm */
/* l,j;a(i){for(l=1,j=0;l<i;i%++l?:(i/=l,j++));l=i==1&&j==3;} */
#if defined GOLFED
l,j;a(i){for(l=1,j=0;l++<i;fmod((float)i/l,l)?i%l?:(i/=l,j++):(j=9));l=i==1&&j==3;}
#else 
int looker, jcount;
int a( intval ) {
  for( looker = 1, jcount = 0; 
    looker++ < intval; 
    /* Watch odd intvals and even lookers, as well. */
    fmod( (float)intval/looker, looker )  
      ? intval % looker /* remainder? */
        ? 0 /* dummy value */
        : ( inval /= looker, jcount++ /* reduce the parameter, count factors */ ) 
      : ( jcount = 9 /* kill the count */ ) 
  )
    /* empty loop */;
  looker = intval == 1 && jcount == 3; /* reusue looker for implicit return value */
}
#endif
/* for (( i=0; $i < 100; i = $i + 1 )) ; do echo -n at $i; ./sphenic $i ; done */
```
I borrowed betseg's previous answer to get to my version.
This is my version of betseg's algorithm, which I golfed to get to my solution:
```
/* betseg's repaired program for sphenic numbers
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int sphenic( int candidate )
{
  int probe, found, dups;
  for( probe = 2, found = dups = 0; probe < candidate && !dups; /* empty update */ ) 
  { 
    int remainder = candidate % probe;
    if ( remainder == 0 ) 
    {
      candidate /= probe;
      ++found;
      if ( ( candidate % probe ) == 0 )
        dups = 1;
    }
    ++probe;
  } 
  return ( candidate == probe ) && ( found == 2 ) && !dups;
}
int main( int argc, char * argv[] ) { /* Make it command-line callable: */
  int parameter;
  if ( ( argc > 1 ) 
       && ( ( parameter = (int) strtoul( argv[ 1 ], NULL, 0 ) ) < ULONG_MAX ) ) {
    puts( sphenic( parameter ) ? "true" : "false" );
  }
  return EXIT_SUCCESS; 
}
/* for (( i=0; $i < 100; i = $i + 1 )) ; do echo -n at $i; ./sphenic $i ; done */
```
[Answer]
# Javascript (ES6), 87 bytes
```
n=>(a=(p=i=>i>n?[]:n%i?p(i+1):[i,...p(i,n/=i)])(2)).length==3&&a.every((n,i)=>n^a[i+1])
```
Example code snippet:
```
f=
n=>(a=(p=i=>i>n?[]:n%i?p(i+1):[i,...p(i,n/=i)])(2)).length==3&&a.every((n,i)=>n^a[i+1])
for(k=0;k<10;k++){
  v=[30,121,231,154,4,402,79,0,60,64][k]
  console.log(`f(${v}) = ${f(v)}`)
}
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~135~~ 121 bytes
* Quite long since this includes all the procedures: prime-check, obtain-prime factors and check sphere number condition.
```
lambda x:(lambda t:len(t)>2and t[0]*t[1]*t[2]==x)([i for i in range(2,x)if x%i<1and i>1and all(i%j for j in range(2,i))])
```
[Try it online!](https://tio.run/##XYwxDsIwEAR7XnFNpDtE4bi0cD7iuDBKAheZS2K5MK83JKJANLtbzM76yo9FdN1sX2N43oYAxeB3ZRNHwUydDjJAdsqfs2v30N7aQugYpiUBAwukIPcR9aUQT1Aavrb7ibujQozIzXzQ8y/NRJ7qv0QpMif4eDZkMmtiycD1DQ "Python 2 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 59 bytes
```
lambda x:6==sum(5*(x/a%a+x%a<1)+(x%a<1)for a in range(2,x))
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaHCyszWtrg0V8NUS6NCP1E1UbtCNdHGUFNbA0Kn5RcpJCpk5ikUJealp2oY6VRoav4vKMrMK1FI0zAxMNL8DwA "Python 2 – Try It Online")
[Answer]
# J, 23 bytes
```
0:`((~.-:]*.3=#)@q:)@.*
```
[Try it online!](https://tio.run/##y/r/P91WT0HBwCpBQ6NOT9cqVkvP2FZZ06HQStNBT4urAChpbKBgZGyoYGhqomBiYMSVBhSyUDA0MlQwUTC3VDBQMAMiEwWu1OSMfIV0hQIYI@3/fwA "J – Try It Online")
Handling 8 and 0 basically ruined this one...
`q:` gives you all the prime factors, but doesn't handle 0. the rest of it just says "the unique factors should equal the factors" and "the number of them should be 3"
[Answer]
# PHP, 66 bytes:
```
for($p=($n=$a=$argn)**3;--$n;)$a%$n?:$p/=$n+!++$c;echo$c==7&$p==1;
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/285093bffbdb0bb5f7ac3cb1125b6bbb91c4f5e1).
Infinite loop for `0`; insert `$n&&` before `--$n` to fix.
**breakdown**
```
for($p=($n=$a=$argn)**3;    # $p = argument**3
    --$n;)                  # loop $n from argument-1
    $a%$n?:                     # if $n divides argument
        $p/=$n                      # then divide $p by $n
        +!++$c;                     # and increment divisor count
echo$c==7&$p==1;            # if divisor count is 7 and $p is 1, argument is sphenic
```
**example**  
argument = `30`:  
prime factors are `2`, `3` and `5`  
other divisors are `1`, 2\*3=`6`, 2\*5=`10` and 3\*5=`15`  
their product: `1*2*3*5*6*10*15` is `27000` == `30**3`
[Answer]
# VB.NET (.NET 4.5), 104 bytes
```
Function A(n)
For i=2To n
If n Mod i=0Then
A+=1
n\=i
End If
If n Mod i=0Then A=4
Next
A=A=3
End Function
```
I'm using the feature of VB where the function name is also a variable. At the end of execution, since there is no return statement, it will instead pass the value of the 'function'.
The last `A=A=3` can be thought of `return (A == 3)` in C-based languages.
Starts at 2, and pulls primes off iteratively. Since I'm starting with the smallest primes, it can't be divided by a composite number.
Will try a second time to divide by the same prime. If it is (such as how 60 is divided twice by 2), it will set the count of primes to 4 (above the max allowed for a sphenic number).
[Try It Online!](https://tio.run/##hdJRS8MwEAfw596nOPYgK1JJ02xjDxGCOhhYXxz44ku3ZXrQXaBNxW9fY1UMKCRvCb/8udzljfqhaYt909OhYOuLs2M31u44tBbrEm7pjIRNj8Tevthu3Ax88OQYzZxz2LgOScudQ4btCRnDzXAgdq@WwVzqEvhZE9zxEbenPwKNVvBg3z0YbXQ1sZ/8MXsc9lg3xJBlN45719qrp468vSe281klEItrnOFFqKQSeQ4Zfq9/dCnLXx02CS6riIdNKn2hovSFSnCFUelJLGSEhUzw1TrKXq0TWsSVpHq4jDu@TGoV6@mVn@MNQ53G/PXDxg8)
[Answer]
# JavaScript (ES6), 80 bytes
```
n=>(p=(n,f=2)=>n%f?p(n,f+1):f,(a=p(n))<n&&(b=p(n/=a))<n&&(c=p(n/=b))==n&a<b&b<c)
```
Using a recursive function to get the smaller factor.  
Output 1 if sphenic, false if there are 2 or less factors and 0 otherwise
**Test**
```
F=
n=>(p=(n,f=2)=>n%f?p(n,f+1):f,(a=p(n))<n&&(b=p(n/=a))<n&&(c=p(n/=b))==n&a<b&b<c)
;[30,121,231,154,4,402,79,0,60,64,8,210].forEach(
  x=>console.log(x,F(x))
)
```
[Answer]
# Dyalog APL, ~~51~~ ~~49~~ ~~48~~ ~~46~~ ~~45~~ 43 bytes
```
1∊((w=×/)∧⊢≡∪)¨(⊢∘.,∘.,⍨){⍵/⍨2=≢∪⍵∨⍳⍵}¨⍳w←⎕
```
[Try it online!](http://tryapl.org/?a=%7B1%u220A%28%28w%3D%D7/%29%u2227%u22A2%u2261%u222A%29%A8%28%u22A2%u2218.%2C%u2218.%2C%u2368%29%7B%u2375/%u23682%3D%u2262%u222A%u2375%u2228%u2373%u2375%7D%A8%u2373w%u2190%u2375%7D30&run) (modified so it can run on TryAPL)
I wanted to submit one that doesn't rely on the dfns namespace whatsoever, even if it is **long**.
[Answer]
# J, ~~15~~ ~~14~~ 19 bytes
Previous attempt: `3&(=#@~.@q:)~*`
Current version: `(*/*3=#)@~:@q: ::0:`
# How it works:
```
(*/*3=#)@~:@q: ::0:  Input: integer n
               ::0:  n=0 creates domain error in q:, error catch returns 0
            q:       Prime factors of n
         ~:@         Nub sieve of prime factors 1 for first occurrence 0 for second
(*/*3=#)@            Number of prime factors is equal to 3, times the product across the nub sieve (product is 0 if there is a repeated factor or number of factors is not 3)
```
This passes for cases 0, 8 and 60 which the previous version didn't.
[Answer]
# Regex (ECMAScript), 46 bytes
```
^((?=(xx+?)\2*$)(?=(x+)(\3+$))\4(?!\2+$)){3}x$
```
[Try it online!](https://tio.run/##TY/BbsIwEER/BSIEu6QJCdAecE1OPXDh0B6bVrJgcdwax7INpFC@PQ2VKvU2ozfS6H2Io/Abp2xIvFVbcvvafNJX67ihU@@Z5FNjAc58ORm37wAFh6aJCyyn4wH@thihnMUDxHIORb@c3uJldm0G7XhyxjTUL8EpIwFTr9WG4OEumSMyzzN2qpQmAM0dia1WhgCxz81Ba7xIrlNvtQowSkbI1A7AcJlqMjJUuJx@fyu/FmtQ3ArnaWUCyNfsDfEP0H9glnmRL24YQ@XqU7QyR6HVtueEkbToRbFmu9oBU4@cmIpj7A6jJkodWRIBFKZ7ETYVuE7OD4e2Uwpws8iZPQQfXDdh12ubJfl9lv0A "JavaScript (SpiderMonkey) – Try It Online")
This works similarly to [Match strings whose length is a fourth power](https://codegolf.stackexchange.com/questions/19262/match-strings-whose-length-is-a-fourth-power/21951#21951) and very similarly to part of [Is this a consecutive-prime/constant-exponent number](https://codegolf.stackexchange.com/questions/164911/is-this-a-consecutive-prime-constant-exponent-number/179412#179412):
```
^
(                   # Loop the following:
    (?=(xx+?)\2*$)  # \2 = smallest prime factor of tail
    (?=
        (x+)(\3+$)  # \3 = tail / {smallest prime factor of tail}; \4 = tool to make tail = \3
    )\4             # tail = \3
    (?!\2+$)        # assert that tail is no longer divisible by \2
){3}                # Execute the loop exactly 3 times
x$                  # assert tail == 1
```
]