[Question]
  [
# The Task
Given a natural number as input, your task is to output a truthy or falsey value based on whether the input is a factorial of any natural number. You can assume that the input number will always be in the range of numbers supported by your language, but you must not [abuse native number types to trivialize the problem](//codegolf.meta.stackexchange.com/a/8245).
[Standard Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
---
## Input
You'll be given a natural number (of type `Integer` or similar).
You can take input in any way you want except assuming it to be in a predefined variable. Reading from file, console, dialog box (`prompt`), input box etc. is allowed. Input as function argument is allowed as well!
---
## Output
Your program should output a truthy or falsey value based on whether the input number is a factorial of any natural number.
Make sure that your truthy/falsey values are consistent for all inputs, i.e, if you are using pair of 1 and 0 to denote truthy and falsey values respectively, then your program must output 1 for all inputs that should have truthy values and 0 for all inputs that should have falsey values.
You can take output in any way you want except writing it to a variable. Writing to file, console, screen etc. is allowed. Function `return` is allowed as well!
Your program must not produce errors for any input!
---
## Test Cases
```
Input     Output
1         Truthy (0! or 1!)
2         Truthy (2!)
3         Falsey
4         Falsey
5         Falsey
6         Truthy (3!)
7         Falsey
8         Falsey
24        Truthy (4!)
120       Truthy (5!)
```
---
## Winning Criterion
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins!
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 1 byte
```
·∏ü
```
[Try it online!](https://tio.run/nexus/brachylog2#dYtRFQRBCMMsQYHSql0ba@eUzI2BzV9fmvN7n3OOq0DkdJe7c0AlbZQ0BLkR7dgcU2DXtcimxjBLHuSOLwXYOQy576G8vGtSEDFFrxHCArUjTKZuG06KHR/8AQ "Brachylog ‚Äì TIO Nexus")
### Explanation
`·∏ü` is a built-in that asserts the following relation: its output is the factorial of its input. We simply give it a set output and see whether it suceeds or not with a variable input.
[Answer]
# ECMAScript Regex, ~~733‚öõ~~ ~~690‚öõ~~ ~~158~~ ~~119~~ ~~118~~ 92 bytes
* *dropped 1 byte (119 ‚Üí 118) using a trick found by [Grimmy](https://codegolf.stackexchange.com/users/6484/grimmy) that can futher shorten division in the case that the quotient is guaranteed to be greater than or equal to the divisor*
* *dropped 26 bytes (118 ~~(117üêå)~~ ‚Üí 92) thanks to [Grimmy in collaboration with H.PWiz](https://chat.stackexchange.com/transcript/message/50183034#50183034). I've finally analyzed, commented, and proved this version.*
My interest in regex has been sparked with renewed vigor after over 4¬Ω years of inactivity. As such, I went in search of more natural number sets and functions to match with unary ECMAScript regexes, resumed improving my regex engine, and started brushing up on PCRE as well.
I'm fascinated by the alienness of constructing mathematical functions in ECMAScript regex. Problems must be approached from an entirely different perspective, and until the arrival of a key insight, it's unknown whether they're solvable at all. It forces casting a much wider net in finding which mathematical properties might be able to be used to make a particular problem solvable.
Matching factorial numbers was a problem I didn't even consider tackling in 2014 ‚Äì or if I did, only momentarily, dismissing it as too unlikely to be possible. But last month, I realized that it could be done.
As with my other ECMA regex posts, I'll give a **warning:** I highly recommend learning how to solve unary mathematical problems in ECMAScript regex. It's been a fascinating journey for me, and I don't want to spoil it for anybody who might potentially want to try it themselves, especially those with an interest in number theory. [See this earlier post](https://codegolf.stackexchange.com/a/178889/17216) for a list of consecutively spoiler-tagged recommended problems to solve one by one.
So **do not read any further if you don't want some advanced unary regex magic spoiled for you**. If you do want to take a shot at figuring out this magic yourself, I highly recommend starting by solving some problems in ECMAScript regex as outlined in that post linked above.
This was my idea:
> 
>  The problem with matching this number set, as with most others, is that in ECMA it's usually not possible to keep track of two changing numbers in a loop. Sometimes they can be multiplexed (e.g. powers of the same base can be added together unambiguously), but it depends on their properties. So I couldn't just start with the input number, and divide it by an incrementally increasing dividend until reaching 1 (or so I thought, at least).  
> 
>   
> 
>  Then I did some research on the multiplicities of prime factors in factorial numbers, and learned that there's [a formula for this](https://janmr.com/blog/2010/10/prime-factors-of-factorial-numbers/) ‚Äì and it's one that I could probably implement in an ECMA regex!
> 
> 
> 
After stewing on it for a while, and constructing some other regexes in the meantime, I took up the task of writing the factorial regex. It took a number of hours, but ended up working nicely. As an added bonus, the algorithm could return the inverse factorial as a match. There was no avoiding it, even; by the very nature of how it must be implemented in ECMA, it's necessary to take a guess as to what the inverse factorial is before doing anything else.
The downside was that this algorithm made for a very long regex... but I was pleased that it ended up requiring a technique used in my 651 byte multiplication regex (the one that ended up being obsolete, because a different method made for a 50 byte regex). I had been hoping a problem would pop up that required this trick: Operating on two numbers, which are both powers of the same base, in a loop, by adding them together unambiguously and separating them at each iteration.
But because of the difficulty and length of this algorithm, I used molecular lookaheads (of the form `(?*...)`) to implement it. That is a feature not in ECMAScript or any other mainstream regex engine, but one that I had [implemented in my engine](https://github.com/Davidebyzero/RegexMathEngine/commit/db4e4a266d55ec66663ccaa17de944508ace4067). Without any captures inside a molecular lookahead, it's functionally equivalent to an atomic lookahead, but with captures it can be very powerful. The engine will backtrack into the lookahead, and this can be used to conjecture a value which cycles through all possibilities (for later testing) without consuming characters of the input. Using them can make for a much cleaner implementation. (Variable-length lookbehind is for most uses at least equal in power to molecular lookahead, but the latter tends to make for more straightforward and elegant implementations. Molecular lookahead may also be able to do things in loops that aren't possible with variable-length lookebehind.)
So the 733 and 690 byte lengths do not actually represent ECMAScript-compatible incarnations of the solution ‚Äì hence the "‚öõ" after them; it's surely possible to port that algorithm to pure ECMAScript (which would increase its length quite a bit) but I didn't get around to it... because I thought of a much simpler and more compact algorithm! One that could easily be implemented without molecular lookaheads. It's also significantly faster.
This new one, like the previous, must take a guess at the inverse factorial M, cycling through all possibilities and testing them for a match. It divides N by 2 to make room for the work it needs to do, and then seeds a loop in which it will repeatedly divide the input by a divisor that starts at 3 and increments up to M-1.\* (As such, 1! and 2! can't be matched by the main algorithm, and must be dealt with separately.) The divisor is kept track of by adding it to the running quotient; these two numbers can be unambiguously separated because, assuming M! == N, the running quotient will continue to be divisible by M until it equals M.
\*But it later turned out that starting the divisor at M-1, and decrementing down to 3, can result in a shorter regex. This was part of golfing 118 ‚Üí 92 bytes.
> 
>  This regex does division-by-a-variable in the innermost portion of the loop. The division algorithm is the same as in my other regexes (and similar to the multiplication algorithm): for A‚â§B, A\*B=C if any only if C%A=0 and B is the largest number which satisfies B‚â§C and C%B=0 and (C-B-(A-1))%(B-1)=0, where C is the dividend, A is the divisor, and B is the quotient. (A similar algorithm can be used for the case that A‚â•B, and if it is not known how A compares to B, one extra divisibility test is all that is needed.)
> 
> 
> 
So I love that the problem was able to be reduced to even less complexity than my golf-optimized [Fibonacci regex](https://codegolf.stackexchange.com/a/178956/17216), but I do sigh with disappointment that my multiplexing-powers-of-the-same-base technique will have to wait for another problem that actually requires it, because this one doesn't. It's the story of my 651 byte multiplication algorithm being supplanted by a 50 byte one, all over again!
With no further ado, here's the regex:
True/false version (**92 bytes**):
`^(((x+)\3+)(?=\3\3\2$)(x(?=\3+(x*))(?=\5+$)(?=((x+)(?=\5\7*$)x)\6*$)\3+(?=\5\7$))*\3xx|x?)x$`
[Try it online!](https://tio.run/##TY9Lb8IwEITv/RU0imA3aUIgPCRcw6mHXji0x6aVLDCJW@NEtgGXx29Pk1SVqj2MZuaTVvPJjsxstKhsZCqx5Xpfqi/@XWuq@Kn3wvMnVwGc6XIY1B8A4ELM0hBhRbO0ubGP4DoTgguwy6eh32rHdj6bBz46zGaNtOBv5iMGWerc1a3Q@XUwPGNsy1erhcoBYyPFhsPsIZogEkMTciqE5ACSas62UigOiPdUHaTES05lbCopLAyiARKxA1A0jyVXuS1wOb5ehVmzNQhaMW34s7KQvyXviH8F/1@o5Wg1WrQ12kKXJ@9ZHZkU255mKueLnhdKsis1EPFIORFhiM1Dz3mx5hVnFgTGe2Y3BWjEi@n3q2aShXbFiFQHa6xuEHK71Uk0T5O7aTJJfgA "JavaScript (SpiderMonkey) ‚Äì Try It Online")
Return inverse factorial or no-match (109 bytes):
`^(?=((x(x*))\2+)(?=\2\2\1$)(x(?=\2+(x*))(?=\5+$)(?=((x+)(?=\5\7*$)x)\6*$)\2+(?=\5\7$))*\2xxx$)(\3|xx)?x|^xx?$` (relies on ECMAScript [no-empty-optional](https://github.com/Davidebyzero/RegexMathEngine/issues/1) behavior)
[Try it online!](https://tio.run/##TU9LbsIwEN33FGkUkZmkhCT8JFKTVRdsWLTLpkgWmODWmMg24PLZ9gA9Yi9CkyKkahYz7yPNe@90R/Vc8cq0dcUXTK038oN9XhSRbO88s/LJVgAHMu4ElxnkBMCCDRCLNMQaFmk9iYc124DwT2vOfujh1X719Yth4KHFYlCvxnjlPMSgSK21tbvonqzF3J5m1ubeJegcMDKbF6O4LAEjLficweCh3UPMNImz/YoLBiCIYnQhuGSAeE/kVgg8lkREuhLcgN/2MeNLAEnKSDBZmhWO09OJ6ymdAicVVZpNpIHyNX5DvAnsvyDHSZ6MGhnNSm327kTuqOALR1FZspHjhiJbbhRk/JGwjIch1g/XxLVupFjFqAGO0Zqa@QoU4lG3WlVdykDTI8mqrdFGAQ995@fr2/HDdZ3kFjU7ny9xe9iN7/pxL77rxd00/gU "JavaScript (SpiderMonkey) ‚Äì Try It Online")
Return inverse factorial or no-match, in [ECMAScript + `\K`](https://github.com/Davidebyzero/RegexMathEngine/commit/c24020605295aa562e7a67290f3d78c69481d0e3) (103 bytes):
`^(((x(x*))\3+)(?=\3\3\2$)(x(?=\3+(x*))(?=\6+$)(?=((x+)(?=\6\8*$)x)\7*$)\3+(?=\6\8$))*x\Kxx(\K\4)?|x?)x$` (relies on ECMAScript [no-empty-optional](https://github.com/Davidebyzero/RegexMathEngine/issues/1) behavior)
Return inverse factorial or no-match, in [ECMAScript + `(?*)`](https://github.com/Davidebyzero/RegexMathEngine/commit/db4e4a266d55ec66663ccaa17de944508ace4067) (103 bytes):
When adapted to molecular lookahead, this regex can match \$3!\$ in a straightforward way:  
`^(?=(?*(x+))(\1*)(?=\1\1\2$)(x(?=\1+(x*))(?=\4+$)(?=((x+)(?=\4\6*$)x)\5*$)\1+(?=\4\6$))*\1xxx$)\1|^xx?$`
Return inverse factorial or no-match, in ECMAScript + [`(?*)`](https://github.com/Davidebyzero/RegexMathEngine/commit/db4e4a266d55ec66663ccaa17de944508ace4067) + [`\K`](https://github.com/Davidebyzero/RegexMathEngine/commit/c24020605295aa562e7a67290f3d78c69481d0e3) (**99 bytes**):
`^(?*(x+))(\1*)(?=\1\1\2$)(x(?=\1+(x*))(?=\4+$)(?=((x+)(?=\4\6*$)x)\5*$)\1+(?=\4\6$))*xxx\K\1$|^xx?$`
And the free-spaced version with comments:
```
# Match factorial numbers in the domain ^x*$
^                           # N = tail = input
(
    ((x+)\3+)(?=\3\3\2$)    # \3 = conjectured inverse factorial of N if N >= 4! = 24;
                            # \2 = N/2 - \3; assert tail is divisible by \3 and by 2;
                            # assert tail is divisible by a number >= 6;
                            # tail = N/2 + \3;
                            # Note that if N = 3! = 6, \3 will behave differently,
                            # because sticking to the pattern, we'd need \2=0, which
                            # is of course impossible, because we must have \2 >= \3.
                            # However, when N=6, \3=1 happens to result in a match after
                            # zero loop iterations.
    # The loop is seeded: X = N/2; I = \3 - 1; tail = X + I + 1
    # The loop will divide X by the numbers in the range \3-1 downward to 3, inclusive.
    # Since we don't divide by \3 itself, and already divided by 2, if N is factorial,
    # the end result of these divisions will be X = \3.
    (                       # Main loop
        x                   # tail = tail-1 = X + I
        (?=\3+(x*))         # \5 = tail % \3 = I; assert X >= \3
        (?=\5+$)            # assert X is divisible by I; if \3=1, then \5=0,
                            # and the main loop will exit after zero iterations
        (?=
            (               # \6 = tail / \5 = (X+I)/I = X/I + 1
                (x+)        # \7 = \6-1 = X/I; assert X/I >= 1
                (?=\5\7*$)
                x
            )
            \6*$
        )
        \3+(?=\5\7$)        # Prepare the next iteration of the loop: X = \7; I -= 1;
                            # tail = X + I + 1;
                            # Assert that the tail difference is divisible by \3, i.e.
                            # that, with our previous values of X and I:
                            #      X + I - (X/I + I-1 + 1)
                            #    = X/I*(I-1) is divisible by \3
                            # Since I is coprime with I-1, if X was divisible by \3
                            # but X/I is not, then X/I*(I-1) will not be either, so this
                            # indirectly asserts that X/I, our new X, is divisible by \3.
                            # The initial value of X was asserted to be divisible by \3
                            # before the loop started, so by induction, every new value
                            # of X will be asserted to be divisible by \3. This is
                            # important because we use modulo by \3 to recover the value
                            # of I at the beginning of each loop iteration.
                            # And if N = \3! and the previous of I=2 and X was able to be
                            # divided by 2, this will force this iteration of the loop to
                            # fail, and the loop will exit with the values of X and I
                            # backtracked to their values before this iteration, i.e.
                            # with X = \3 and I = 2.
    )*
    \3xx                    # assert tail = \3 + 2 + 1, meaning when the loop finished
                            # we ended up with X = \3 and I = 2
|
    x?                      # match N=1 and N=2, which the main algorithm can't
)
x$
```
The full history of my golf optimizations of these regexes is on github:
[regex for matching factorial numbers - multiplicity-comparing method, with molecular lookahead.txt](https://github.com/Davidebyzero/RegexGolf/blob/master/regex%20for%20matching%20factorial%20numbers%20-%20multiplicity-comparing%20method%2C%20with%20molecular%20lookahead.txt)  
[regex for matching factorial numbers.txt](https://github.com/Davidebyzero/RegexGolf/blob/master/regex%20for%20matching%20factorial%20numbers.txt) (the one shown above)
## Optimized for returning the inverse factorial
The above algorithm has the quirk of happening to match \$3!\$ by coincidence, yielding a false inverse factorial value of \$1\$ instead of \$3\$. This complicates turning the regex into one that returns the inverse factorial as a match.
The below algorithm is cleaner in that it straightforwardly matches \$3!\$ with the correct inverse factorial value. It does however result in a longer true/false regex.
True/false version ‚Äì returns inverse factorial minus 1 in `\1` (**96 bytes**):
`^(x*)(?=x(x\1)*$)((?=\2*(x*)(?=\2)\4(x+))(?=\5+$)(?=((x*)(?=\5\7*$)x)\6*$)\2*(?=x\4\6$)\1)*\1x?$`
[Try it online!](https://tio.run/##TY/NbsIwEITvfQoaIdhNSkhoAInUcOqBC4f2WLeSBSZxaxzLNpDy8@ypUxWpp9XstzOr@WQHZtdGaDewWmy42VXqi383hih@7Lzw4rnWACcyH4bNB9QhwoLUUNMUwy6CF3QU/q3pCGkGdYS/Yhx12wk3OKZT76iRTvxoTT6HZnTihc@iab3oNuHwhLGrXp0RqgCMrRRrDpOHQYaYW5Lkx1JIDiCJ4WwjheKAeE/UXko8F0TGVkvhoD/oYy62AIoUseSqcCXOR5eLsCu2AkE0M5YvlYPiLXlHvAH@H6h5ukhnLUZXmuoYLNWBSbHpGKYKPusEkcy3lYFcPBGeiyhC/zCog9hwzZkDgfGOuXUJBvFsez3tKzloW6S53jvrjD/Jr9cmGUwfk7txkiU/ "JavaScript (SpiderMonkey) ‚Äì Try It Online") - true/false  
[Try it online!](https://tio.run/##TY9NbsIwEIX3PUWKEJlJmpCEABKpYdUFGxbtElPJAhPcGieyDaT8bHuAHrEXoUlVpK5Gbz69N/Pe2J6ZpRalDUwpVlxvC/XOP66aKH5wnnn@VJUARzLuetdXqDyECamgojF6bYRa0MT7W9MEaQqVj7@i77ebCTfYp8PaUSEd1KMx1Tk0pYNa1Fk0ribtq9c9YmiLF6uFygFDI8WSw@AhSBEzQ6LssBGSA0iiOVtJoTgg3hO1kxJPOZGhKaWw4AYuZmINoEgeSq5yu8Fxcj4LM2MzEKRk2vCpspDPowXiDfD/QI3jSTxqMNqNLg6tqdozKVaOZirnI6fly2xdaMjEI@GZ8H2sD25Jq2qFmpecWRAYbpldbkAjnkynU9alLDQ94qzcWWM1CN91vj@/HNffzuPF7dXscrlGwbAX3fWjNLpLo14S/QA "JavaScript (SpiderMonkey) ‚Äì Try It Online") - return value in `\1`
Return inverse factorial or no-match (**103 bytes**):
`^(?=(x*)(?=x(x\1)*$)((?=\2*(x*)(?=\2)\4(x*))(?=\5+$)(?=((x*)(?=\5\7*$)x)\6*$)\2*(?=x\4\6$)\1)*\1x?$)x\1`
[Try it online!](https://tio.run/##TY9NbsIwEIX3PUUaIZhJSkgggERqWHXBhkW7rFvJApO4dUxkG0j52fYAPWIvQp2qSF29efNpZt68sR0zSy0q2zWVWHFdbtQ7/7hoovjee@T5Q10BHMi0F1xeYUagDtBJDTVNMGghOEP7wV@b9pGmTf1rhmGrUbjCIR27iRrpyEkz5PbQlI6ccbtoUs8cpckl6B0wspsnq4XKASMjxZLD6K6bImaGxNm@EJIDSKI5W0mhOCDeErWVEo85kZGppLDQ6XYwE2sARfJIcpXbAqf900mYBVuAIBXThs@Vhfw5fkG8Av4fqGkySyYNRlvozd6fqx2TYuVppnI@8fxQZuuNhkzcE56JMER3sCR@7UeaV5xZEBiVzC4L0IhH025X7ikLzR9JVm2tsRpE2PG@P7@8Tli6JNeo2fl8ibvjQXwzjNP4Jo0H/fgH "JavaScript (SpiderMonkey) ‚Äì Try It Online")
Return inverse factorial in `\1` or no-match, in [ECMAScript + `(?*)`](https://github.com/Davidebyzero/RegexMathEngine/commit/db4e4a266d55ec66663ccaa17de944508ace4067) (**97 bytes**):
`^(?*(x(x*))\1*$)\2((?=\1*(x*)(?=\1)\4(x*))(?=\5+$)(?=((x*)(?=\5\7*$)x)\6*$)\1*(?=x\4\6$)\2)*\2x?$`
Return inverse factorial or no-match, in [ECMAScript + `\K`](https://github.com/Davidebyzero/RegexMathEngine/commit/c24020605295aa562e7a67290f3d78c69481d0e3) (**101 bytes**):
`^(x*)(?=x(x\1)*$)((?=\2*(x*)(?=\2)\4(x(x*)))(?=\5+$)(?=((x*)(?=\5\8*$)x)\7*$)\2*\4(?=x\7$)\K\6)*\1x?$`
Return inverse factorial minus 1 or no-match, in [ECMAScript + `\K`](https://github.com/Davidebyzero/RegexMathEngine/commit/c24020605295aa562e7a67290f3d78c69481d0e3) (**98 bytes**):
`^(x*)(?=x(x\1)*$)((?=\2*(x*)(?=\2)\4(x+))(?=\5+$)(?=((x*)(?=\5\7*$)x)\6*$)\2*(?=x\4\6$)\1)*x?\K\1$`
```
# Match factorial numbers in the domain ^x*$ and return the inverse factorial as the match
^                           # N = tail = input
(?=
    (x*)                    # \1 = conjectured inverse factorial - 1; tail -= \1
    (?=x(x\1)*$)            # \2 = conjectured inverse factorial; assert \2 divides N;
                            #      assert N >= 2 * \2;
                            # If N=1 or N=2, then \2 will be unset (having experienced 0
                            # iterations of its mini-loop) and \1=0 or \1=1, respectively
    # The loop is seeded: X = N; I = \1; tail = X - I
    # The loop will divide X by the numbers in the range \2-1 downward to 2, inclusive.
    # We don't divide by \2 itself, so if N is factorial, the end result of these
    # divisions will be X = \2 - 1.
    (
        (?=
            \2*(x*)(?=\2)   # \4 = tail % \2 = \2-I; assert tail >= \2
            \4(x*)          # \5 = \2-\4 = I
        )
        (?=\5+$)            # assert X is divisible by I
        (?=
            (               # \6 = tail / \5 = (X-I)/I = X/I - 1
                (x*)        # \7 = \6-1
                (?=\5\7*$)
                x
            )
            \6*$
        )
        \2*(?=x\4\6$)\1     # Prepare next iteration of loop: X = \6+1; I -= 1;
                            # tail = X - I;
                            # Assert that, with our previous values of X and I:
                            #      (X - I) - (1 + \2-I + X/I - 1)
                            #    = X - \2 - X/I                   is divisible by \2
                            # Assuming X was already divisible by \2, this asserts
                            # X/I is also divisible by \2. The initial value of X was
                            # asserted to be divisible by \2, so by induction, every
                            # new value of X will be asserted to be divisible by \2.
                            # This is important because we use modulo by \2 to recover
                            # the value of I at the beginning of each loop iteration.
                            # And if I = 1, this iteration of the loop will fail
                            # because in this case,
                            #      1 + \4 + \6 > tail
                            #      \2-I + X/I > X - I
                            #      \2 > 0
                            # and the loop will exit with I = 1.
                            # But note that if N = \2!, then when we reach I = 1, and
                            # thus have X = \2 and tail = \2 - 1, this iteration of the
                            # loop will have already failed at its beginning due to the
                            # assertion that tail >= \2.
    )*
    \1x?$                   # assert tail = \1 = \2-1, meaning when the loop finished we
                            # ended up with X = \2 and I = 1,
                            # or tail = \1+1 (what would be \2), which can only happen if
                            # \2 is unset and N=1 or N=2 and the loop did 0 iterations.
)
x\1                         # return \1 + 1 as a match; don't use \2 because it will be
                            # unset in the case of N=1 or N=2
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
≈í?IE
```
Not the shortest Jelly answer, but it's rather efficient.
[Try it online!](https://tio.run/nexus/jelly#@390kr2n639DAxA43H54QlqkwsMd2x81zFFwzMlRSEtMLskvykzMKVZISs3JL1cAKtQBqtT7DwA "Jelly ‚Äì TIO Nexus")
### How it works
```
≈í?IE  Main link. Argument: n
≈í?    Yield the n-th permutation of the positive integers, without the sorted tail.
      For 120, this yields [5, 4, 3, 2, 1], the tail being [6, 7, 8, ...].
  I   Increments; compute all forward differences.
      For 120, this yields [-1, -1, -1, -1].
   E  Check if all differences are equal.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
!‚Ç¨ƒã
```
[Try it online!](https://tio.run/nexus/jelly#@6/4qGnNke7///8bGhkAAA "Jelly ‚Äì TIO Nexus")
1 for yes, 0 for no.
## How it works
```
!‚Ç¨ƒã  argument as z
!‚Ç¨   [1!, 2!, 3!, ..., z!]
  ƒã  count the number of occurrence of z
```
[Answer]
## JavaScript (ES6), ~~30~~ ~~29~~ 28 bytes
Expects a positive integer. Returns `-1` for falsy and `-2` for truthy.
```
f=(n,k=2)=>n>1?f(n/k,k+1):~n
console.log(1,  '-->',f(1))   // Truthy (0! or 1!)
console.log(2,  '-->',f(2))   // Truthy (2!)
console.log(3,  '-->',f(3))   // Falsey
console.log(4,  '-->',f(4))   // Falsey
console.log(5,  '-->',f(5))   // Falsey
console.log(6,  '-->',f(6))   // Truthy (3!)
console.log(7,  '-->',f(7))   // Falsey
console.log(8,  '-->',f(8))   // Falsey
console.log(24, '-->',f(24))  // Truthy (4!)
console.log(120,'-->',f(120)) // Truthy (5!)
```
**Note**: This function supports pretty large inputs (you should read this as: 'pretty large for JS'). It should work safely up to *253 - 1*. It will fail for sure starting at *N = 121,645,100,408,831,992*, this input being rounded to *19! = 121,645,100,408,832,000* because of its IEEE-754 encoding. There *may* be other false positive results before *121,645,100,408,831,991* because of rounding errors, but I don't know for sure.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~39~~ 38 bytes
```
f=lambda n,i=1:n>1and f(n/i,i+1)or n<1
```
A recursive function taking an integer, `n`, returning a boolean value inversley representing the result (truthy: `False`, falsey: `True`)
**[Try it online!](https://tio.run/nexus/python3#FYzNCoMwEAbP@hR7M8Gv6Kb@FKm@S8QGFnQVm/ePehoGhklhXP02L54UMvKgE3tdKBitBFKy3U/SL6dwM/7@kUTJMBzeaNCiQ48PXAN2tR3y7DhFo3lCUPGaCtynx6xNFw)**
Repeatedly divides `n` by `i`, with an initial value of `1`, until the remainder is less than or equal to `1` then tests if that remainder is less then `1`, only factorials will end with a remainder equal to `1`, and `<` is a byte shorter than `==`.
[Answer]
# Java 8, 46 bytes
```
i->{int j=1,c=0;for(;j<i;j*=++c);return j==i;}
```
This is based on Roman Gr√§f's entry that I was able to knock a dozen or so bytes off of. I would have suggested it there but I don't have enough reputation to comment yet! My modified test runner code:
```
import java.util.function.Function;
import java.util.stream.IntStream;
public class IsFactorial {
    public static Function<Integer, Boolean> isFactorial = i->{int j=1,c=0;for(;j<i;j*=++c);return j==i;};
    public static int[] truthyCases = {1,2,6,24,120};
    public static int[] falsyCases = {3,4,5,7,8};
    public static void main(String[] args){
        System.out.println(
            IntStream.of(truthyCases).allMatch(i->isFactorial.apply(i)) &&
            IntStream.of(falsyCases).allMatch(i->!isFactorial.apply(i)));
    }
}
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~50~~ 38 bytes
*12 bytes saved thanks to @Neil by combining shortening the loop and by getting rid of the `;`*
```
.+
1¬∂$&$*
+`^(1+)¬∂(\1)+$
1$1¬∂$#2$*
¬∂.$
```
[Try it online!](https://tio.run/##Fcu7DcIwFIbR/luDC3KwFOW/dl4TsARCoaCgoUDM5gG8mBPqo/N9/d6fZzuH29b6iGqxi12J2yModrWEu7poyP5y8oNq6a014SQyIxMzCysakJCjhDIa0YRmtKAVH/DjOJ7wvAM "Retina ‚Äì Try It Online")
Outputs `1` for true and `0` for false.
`.+` matches the entire number
`1¬∂$&$*` replacing it with `1` followed by a newline and the match converted to unary
The remaining program divides the unary number in the bottom line by successively increasing positive integers, kept track in the top line, while it is possible to do so.
`+`` loop until string remains same
* `^(1+)¬∂(\1)+$` match the top line many `1`s and a multiple of it many `1`s on the bottom line and replace it with
* `1$1¬∂$#2$*` the top line many `1`s with another `1`, that is, increasing the number represented by the top line by 1, followed by the newline and the number of matches of the top line in the bottom line (ie. count of matches of the second capturing group) many `1`s, that is, dividing the bottom number by the top number
Once it is no longer possible to do so,
`¬∂.$` give the number of matches of this regex, ie. does there exist a lone `1` on the bottom line, which only happens if the number is a factorial
---
If no-crash/crash is allowed instead of truthy/falsy values, then I can get ~~36~~ 34 bytes.
```
^
1¬∂
{`.+$
$*
^(1+)¬∂(\1)+$
1$1¬∂$#2
```
This goes by the same approach, but combines the `$*` into the third and fourth lines. The third line onward is a part of the same loop, `{` is short for `+(` where the `(` groups the remaining lines into the loop. Factorials end in the program breaking out of the loop, while non-factorials get stuck in the loop forever until Retina throws an OverflowException caused by the last replacement failing thus having the bottom in unary instead of in decimal, and the first replacement of the loop converts the bottom line from decimal to unary, so it blows up quickly.
[Answer]
# C++, ~~102~~ ~~100~~ 92 Bytes
```
#include<cmath>
int a(int n){int i=n,j=0;for(;i;)j|=lround(exp(lgamma(i--+1)))==n;return j;}
```
Loops through all the values from `0` to `n` and calculates the factorial and then checks if it's equal to `n`.
Thanks Christoph! (saved 8 bytes)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
L!QO
```
[Try it online!](https://tio.run/nexus/05ab1e#@@@jGOj//7@hkQEA "05AB1E ‚Äì TIO Nexus")
**Explanation**
```
L      # range [1 ... input]
 !     # calculate factorial of each
  Q    # compare with input for equality
   O   # sum
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~43~~ 26 bytes
```
f n=elem n$scanl1(*)[1..n]
```
[Try it online!](https://tio.run/nexus/haskell#DchNCoAgEAbQq3wLFyVDNP0vsotIC4kCQQepVl3eXL6XL4g5wxkh6jmcBK50bblpZM/ReTHp9vJC4fMJq94QXcJVbJnQEXrCQBgJE2EmLCWLuWv3/AM "Haskell ‚Äì TIO Nexus")
* Saved 17 bytes, thanks to [Laikoni](https://codegolf.stackexchange.com/users/56433/laikoni)
[Answer]
# [Haskell](https://www.haskell.org/), 38 bytes
```
m#n=n<2||mod n m<1&&(m+1)#div n m
(2#)
```
[Try it online!](https://tio.run/nexus/haskell#XYw7CsMwEAX7nGLBwdik2Z9Wu2AfJmAMLqSEEFL57orSZro3D6aVoa514fMsjw0qlIXGcSo3moft@PzEZV8nHuZW7keFFZ6vo77hCjuQJnLBYGRnT25hopgxu6KbYJcaLllRcjAro0tyV8tOKau5o1EEiQYl6zc6oiXuASPWPv5pXw "Haskell ‚Äì TIO Nexus") Example usage: `(2#) 24`. Returns `True` or `False`. 
This is the shortest I could get while still being very efficient. Even for numbers as large as 
```
145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000
```
the result is immediately given. The solution works by dividing the input `n` by `m = 2,3,4,5,...` until either the result is one or `n` is not divisible by `m`.
For the shorter but incredible inefficient 26-byte solution which computes `n!` for inputs that are not factorials look [here](https://codegolf.stackexchange.com/a/121745/56433).
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
t:Ypm
```
[Try it online!](https://tio.run/nexus/matl#@19iFVmQ@/@/oZEBAA "MATL ‚Äì TIO Nexus")
### Explanation
```
t     % Implicit input. Duplicate
:     % Range from 1 to that
Yp    % Cumulative product
m     % Ismember. Implicit display
```
[Answer]
# [Fourier](https://github.com/beta-decay/Fourier), ~~40~~ 39 bytes
```
I~Q1~N(i^~i*N~N{Q}{1~Xo}N>Q{1}{1~X0o}X)
```
[**Try it on FourIDE!**](https://beta-decay.github.io/editor/?code=SX5RMX5OKGlefmkqTn5Oe1F9ezF-WG99Tj5RezF9ezF-WDBvfVgp)
Basically multiplies the number N by an increasing amount until N is either equal to (output 1) or greater than (output 0) the input.
***Explanation Pseudocode:***
```
Q = Input
N = 1
While X != 1
    i += 1
    N = N*i
    If N = Q Then
        Print 1
        X = 1
    End If
    If N > Q Then
        Print 0
        X = 1
    End If
End While
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~8~~ 6 bytes
```
ol x¬•U
```
[Try it online!](http://ethproductions.github.io/japt/?v=1.4.4&code=b2wgeKVV&input=OQ==)
This outputs 0 for false and 1 for true.
# Explanation
```
 ol x¬• U
Uol x==U
Uo       # Create the range [0 ... input]
  l      # Replace each element by its factorial
     ==U # Compare each element to the input (yielding 1 if equal and 0 otherwise)
    x    # And sum the result
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 5 ~~6~~ ~~7~~ bytes
*Golfed a byte by changing `√ó/` to `!` thanks to Erik the Outgolfer*
```
‚ä¢‚àä!‚àò‚ç≥
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///3/FR24RHXYsedXQpPuqY8ah38///j9omVj/q3arjCCRqD60AihmZAAA "APL (Dyalog Unicode) ‚Äì Try It Online")
### Explanation
```
    ‚ç≥                      Range of numbers from 1 to argument, 1 2 3 4 .. n
   !                       Factorial; 1! 2! 3! 4! .. n!
‚ä¢‚àä                         Is the right argument a member of this list?
```
[Answer]
# C++ (clang), ~~51~~ 47 bytes
*-4 bytes thanks to Grimmy*
Recursion wins out as far as golfing goes.
**47 bytes**, with floating point and a global variable:
`int i;int f(double n){return n>1?f(n/++i):i=n;}`
[Try it online!](https://tio.run/##RY7NCsIwEITveYpFERLiTwVPpq0v4iUmjS7ETUnTU@mzx6YKfodhGWaGNX1/MF7TM2ekBKiKOm7D@PAdkJhil8ZIQO355jidpERxxYbUnLdIxo@2g3pIFsPx1bJSfmskLtjEYMGFCHwdbioFWF@qL8stpVgjBXTAHUfxdwp9XJqOb3YWcACnTQoRtb/TZg8o1Jr9vVcpNucP "C++ (clang) ‚Äì Try It Online")
`double` is used instead of `float` because otherwise it'd start giving false positives around 11! (everything from 39916798 to 39916802 would be identified as factorial).
This takes advantage of global variables being initialized (in the case of the integer `i`, to zero).
`i=n` casts a `double` floating point value to `int`. Any `n<1` will be rounded down to `0` (falsey). A value of `1` (truthy) will result if and only if `n==1` exactly.
The function cleans up after its change to the global variable upon finishing its recursion, by setting it to `0` or `1` with `i=n`. Which of those it is makes no difference; an value of `1` will merely result in the initial division by `1` being skipped the next time the function is invoked.
**49 bytes**, with floating point:
`int f(double n,int i=2){return n>1?f(n/i,i+1):n;}`
[Try it online!](https://tio.run/##RY7BDoIwEETvfMUGY9IGVDCeLOKPeKkt1U3qlpRyInx7pWDiO81OZiar@v6grKRXjEgBDNNufNoOqEwn3s588l0YPQG19d0wOmGJRc2vJOa4Q1J21B00Q9Doju82S62PRGI8mzJYMM4D27YqAdhcqo1FFwVfIwk0wAxD/ncSvV@ahuV7DTiAkSo4j9I@KC8BuVizv/cqkc3xCw "C++ (clang) ‚Äì Try It Online")
---
**51 bytes**, zero is true:
`int f(int n,int i=2){return n<2?!n:n%i|f(n/i,i+1);}`
This sacrifices quite a lot of speed for 1 byte of savings. Replace the `|` with `||` to make it fast, due to short-circuit evaluation of the logical OR.
[Try it online!](https://tio.run/##RY7BDoIwEETv/YoFQ9IGVCSeLOqPeGkK1U1wIaWckG@vLZj4DpPNZmZn9TDsdafo6T2SA8OjUhEVr5WYbesmS0B1dU/oQhl@DKcjFpifhFz8Dkl3U9NCPboG@8PrxmL0rZC4YDODgOkt8O1gKQHrc7kR5jwXqyWCBngS@sV/FRlsiBqeZg3gCEZp11tU3YPSAlDI1ft7spRs8V8 "C++ (clang) ‚Äì Try It Online") (51 byte slow version)  
[Try it online!](https://tio.run/##RY7BDoIwEETv/YoVQ9IGVCSeLOqPeGkK1U1wIaWcgG@vLZj4DpPNZGYzuu8PulX08h7JgeFRKY@Kt1JMtnGjJaCqfOzoSinOs@F0whyzs5CL3yPpdqwbqAZXY3d831nsfhQSF2xiEDCdBb59LCRgdSk2wp1lYo1E0ADfhQHib0V6G6qGJ2kNOIBR2nUWVfukJAcUcs3@VhaSLf4L "C++ (clang) ‚Äì Try It Online") (52 byte fast version)
Ungolfed slow version:
```
int isFactorial(int n, int i=2)
// returns 0 for true, and nonzero for false
{
    if (n < 2) // same as "if (n==0 || n==1)" in our natural number input domain
    {
        if (n==0)
            return 1; // not factorial
        else // n==1
            return 0; // is factorial (could be either 0! or 1!)
    }
    // Because any nonzero value represents "false", using "|" here is equivalent
    // to "||", provided that the chain of recursion always eventually ends. And
    // it does always end, because whether or not "n" is factorial, the "n / i"
    // repeated division will eventually give the value of zero or one, satisfying
    // the above condition of termination.
    return (n % i) | isFactorial(n / i, i+1);
}
```
Ungolfed fast version:
```
int isFactorial(int n, int i=2)
// returns 0 for true, and nonzero for false
{
    if (n < 2) // same as "if (n==0 || n==1)" in our natural number input domain
    {
        if (n==0)
            return 1; // not factorial
        else // n==1
            return 0; // is factorial (could be either 0! or 1!)
    }
    if (n % i != 0)
        return 1; // not factorial
    else
        return isFactorial(n / i, i+1);
}
```
There are many ways to rearrange this.
**52 bytes**, nonzero is true:
`int f(int n,int i=2){return n<2?n:n%i?0:f(n/i,i+1);}`
[Try it online!](https://tio.run/##RY7BDoIwEETv/YoNhqQNqNV4oig/4qUpVDfBhZRyInx7bcHEd5hsNjM7a8bxaHpNrxCQPFielMqkeL@KxXV@dgRUXxuqKMdGVpbTGUssLkKt4YBk@rntoJ58i8Pp/WAp@9FIXLCFQcQODvh@USrA@iZ34lwUYrMk0AKP/eK/SYwuJi3P8hZwAquNHxzq/klZCSjU5v09KRVbwxc "C++ (clang) ‚Äì Try It Online")
**52 bytes**, zero is true:
`int f(int n,int i=2){return!n?1:n%i?n-1:f(n/i,i+1);}`
[Try it online!](https://tio.run/##RY7BDoIwEETv/YoVQ9IGUDCeKMqPeGkK1U1wIaWcCN9eWzj4DpPNZGYzepoKPSh6e4/kwPColEfFx02stneLpRO1VU0ptlRUteF0xRyzSsjNn5H0sHQ9NLPrcLx8nix2vwqJC7YyCJjRAj8@lhKwuZcH4c4ysUciaICfwgDxtyKTDVXDk7QDnMEo7UaLanhRkgMKuWePlVBKtvkf "C++ (clang) ‚Äì Try It Online")
---
[Answer]
# Perl 5, 31 bytes
```
$a=<>;$a/=++$i while$a>1;exit$a
```
Input is taken via STDIN, output is given via exit code (1 for factorial, 0 for non-factorial).
The input is divided by successive integers until it's either 1 or some fraction less than one, which is truncated into the result.
[Answer]
# [Perl¬†6](https://perl6.org), 29 bytes
```
{($_,{$_/++$}...2>*).tail==1}
```
[Test it](https://tio.run/nexus/perl6#ZY/faoMwFMbv8xTHIiOpWVat7Upd7K72BF4KRTRlglpp4phInt1F0V2kuTiE3/d9508nBfwcWR6huoeX/F4I4OOA3Ssd3Oub57maMRbEW8JUVlac@3o0xk8lpAIOVdkIiQmrs/Y8IIB6KgDuR9m0nYqNIy28GaVyu0hTdFJwQi4G6cgUb03Qy2JAGnVmtcT8I9RWWQPePDRCt/tjmf8aA07nHE3FbytyJQoC0wqlhOkUPIuEwqpS2Awz08BjGFasN0iPPqwveXTquwe8c8DM8h2CgictMHT/T7@ySooehTY42OD41GhvGr3btpMNgtDOhSbnBzuLHhzyBw "Perl 6 ‚Äì TIO Nexus")
## Expanded:
```
{   # bare block lambda with implicit parameter ÔΩ¢$_ÔΩ£
  (              # generate a sequence
    $_,          # starting with the input
    {
      $_ / ++$   # divide previous element by an ever increasing number
                 # 1,2,3,4,5,6,7,8 ... *
    }
    ...          # keep generating until
    2 > *        # 2 is greater than what was generated
                 # ( 1 or a fractional number )
  ).tail == 1    # check if it ended at 1
}
```
[Answer]
# [setlX](https://randoom.org/Software/SetlX), 32 bytes
```
f:=n|=>exists(x in{0..n}|n==x!);
```
Creates a function called `f` where your use your potential factorial as parameter.
It works with arbitrary integer size but it's fairly inefficient.
[![](https://i.stack.imgur.com/lZHRI.png)](https://i.stack.imgur.com/lZHRI.png)
(by the way: this is my first participation at a programming puzzle)
[Answer]
# C (gcc), 33 bytes
```
e;f(n){n=n%++e?n==!(e=0):f(n/e);}
```
Note that some authors define "natural number" as *positive* integer. Hence I don't care that `f(0)` causes an infinite recursion.
[Answer]
## [><>](https://esolangs.org/wiki/Fish), ~~24~~ 22 bytes
*-2 bytes thanks to @Aaron*
I'm trying a new language (since my Mathematica licence expired‚Ä¶)
```
01\{=n;
?!\$1+:@*:{:}(
```
[Try it online](https://tio.run/nexus/fish#@29gWGZXbZtnzWWoYhOnaK9Ra1VtpeVgpf3//3/dMgVzIwMA "><> ‚Äì TIO Nexus"), or at the [fish playground](https://fishlanguage.com/playground)
Assumes the input number is [already on the stack](https://codegolf.meta.stackexchange.com/a/8493/66104), and returns 0 or 1. It works by multiplying together the first *n* numbers until that stops being less than the input, and then printing 1 if it equals the input, and 0 if it doesn't.
[Answer]
# [R](https://www.r-project.org/), ~~28~~ 22 bytes
```
scan()%in%gamma(1:171)
```
[Try it online!](https://tio.run/##K/r/vzg5MU9DUzUzTzU9MTc3UcPQytDcUPO/oZHBfwA "R ‚Äì Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 68 bytes
```
bool f(System.Numerics.BigInteger n,int k=2)=>n<2||n%k<1&f(n/k,k+1);
```
[Try it online!](https://tio.run/##lY@xTsMwEIb3PMVRAbKpmyahpUhpOsCEBCgSA0PVwTVOuTh1qtgUodTPHhxAHUGcdNt///edMCNRN7ITFTcGcmgDY7lFAfsaX@CBoybGNqg3yxXwZmOoT@Swgwy0fIec0DQYj2HNjT@x0lgQ3EgTFL6Ti1ey5w0goO7Ty1Ubs4Rdsgmbsis2Y9csmbA4idjM7zSaRI4GAE8fxspteFtrU1cyfG7QynvUkpwOWnQwWkC7CwuC1A2@4ZX3ks0X/b/gOPLj@p@O3Me3rWxQmPAGN3fayr66zOLUJ3w3QW1BZUmq5hmmajjsjQHKi0ylf7qfHOVL6oC0paP9Cy5w3bquKyjILw6a/aBpttDz5HDQZ2oenxdEjxVTw5imnes@AQ "C# (.NET Core) ‚Äì Try It Online")
Not the shortest solution, but works with really big numbers. The TIO link includes an example with `10000!`.
Here is a shorter version that uses `int` which has a maximum value of [2147483647](https://docs.microsoft.com/en-us/dotnet/api/system.int32.maxvalue?view=netframework-4.7.2).
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 45 bytes
```
bool f(int n,int k=2)=>n<2||n%k<1&f(n/k,k+1);
```
[Try it online!](https://tio.run/##FY3BasMwEETv/ooltEWiGztW06aQOJdeWzD0kEPIQVHlVNhdBa1IKY6@3VUuAwPvzRieGx/sZAbNDC2MBUcdnYGLd1/woR0JjsHRaX8AHU4sM9HCGRog@wutkOuiquCoOSvRcgSj2XLR5U1tvsVFB3Dg6EbvD2ONCp9wic/4git8RbXEWi1wpRZJFgCffxztT/nmif1gy11w0b47suJuNroE8y2M57ITTqZZ/k3T0fsBcqcIhLfsGyWbLW3U9Ur3/aZ@6ARVPfaPtVxPafoH "C# (.NET Core) ‚Äì Try It Online")
Credit to @KevinCruijssen for golfing 3 bytes in total from both answers!
[Answer]
# [Julia 1.0](http://julialang.org/), 26 bytes
```
x->x in Base._fact_table64
```
Factorial is [implemented as a lookup table](https://github.com/JuliaLang/julia/blob/099e826241fca365a120df9bac9a9fede6e7bae4/base/combinatorics.jl#L1) in Julia, so lets just see if our value is in the table. Accurate for `Int64`, would be wrong for factorials that require a larger Integer type to represent.
[Try it online!](https://tio.run/##yyrNyUw0rPifZpuUmp6Zx/m/QteuQiEzT8EpsThVLz4tMbkkviQxKSfVzOR/al4Kl0NxRn65QpqGoSacaYRgGiOYJgimKYJphmCaI5gWSIYh6TM0MtD8DwA "Julia 1.0 ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 3 bytes
```
√û!c
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLDniFjIiwiIiwiMjQiXQ==)
Updated to 2.16.0
This checks if the input is in an infinite list of factorials. Now you're probably wondering "but what if it isn't in the factorial list? A linear search won't ever terminate it'll just keep on going!" Well Vyxal is smart enough to know that in strictly ascending infinite lists of numbers, you stop once you reach a number bigger than what you're searching for.
[Answer]
## Mathematica, 20 bytes
```
!FreeQ[Range[#]!,#]&
```
other version to test big numbers
(see comments)
```
Range[10^3]!~MemberQ~#&
```
tests up to 1000!
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), 24 bytes
```
U0O@1I1>-?1u>*w;W;@Orq)p
```
[Try it online](https://ethproductions.github.io/cubix/?code=VTBPQDFJMT4tPzF1Pip3O1c7QE9ycSlw&input=MTIw&speed=10)
Cubified
```
    U 0
    O @
1 I 1 > - ? 1 u
> * w ; W ; @ O
    r q
    ) p
```
We start by pushing `1`, `I`nput, `1` onto the stack. These will be our index, our target, and our accumulator, respectively.
We then loop. At each iteration, we subtract the accumulator from the input. If the result is 0, we're done, so we push `1`, `O`utput, and exit. If it's negative, we've gone too far, so we push `0`, `O`utput, and exit. Otherwise, we see
```
;p)*rq;
;         Pop the difference off the stack.
 p)       Move the index to the top of the stack and increment it.
   *      Multiply the accumulator by the index to get the next factorial.
    rq;   Put the stack back in the right order.
```
[Answer]
# TI-BASIC, 13 bytes
```
sum(Ans=seq(X!,X,1,69
```
Input is an integer in Ans.  
Output is 1 if the input is a factorial, 0 if not.
Due to precision in `=` checks being limited to 10 decimal places, this program will produce erroneous answers for numbers whose length is \$>10\$ digits.
**Explanation:**
```
        seq(X!,X,1,69  ;generate a list of all factorial numbers that
                       ;  TI-BASIC can store
    Ans=               ;equality check of the input against all members,
                       ;  1 if true, 0 if false
sum(                   ;sum the elements in the list
                       ;leave the result in Ans
                       ;implicit print of Ans
```
**Examples:**
```
720:prgmCDGF27
               1
25:prgmCDGF27
               0
```
**Note:** TI-BASIC is a tokenized language. Character count does *not* equal byte count.
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), 3 bytes
```
?$!
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/315F8f9/IxMA "cQuents ‚Äì Try It Online")
As I said in another question, cQuents is made for this.
```
?   # Query (Outputs if in the sequence)
 $! # Factorial
```
]