[Question]
  [
Not to be confused with [Find the factorial!](https://codegolf.stackexchange.com/questions/607/find-the-factorial)
## Introduction
The factorial of an integer `n` can be calculated by
$$n!=n\times(n-1)\times(n-2)\times(...)\times2\times1$$
This is relatively easy and nothing new. However, factorials can be extended to [double factorials](https://en.wikipedia.org/wiki/Double_factorial), such that
$$n!!=n\times(n-2)\times(n-4)\times(...)\times4\times2$$
for even numbers, and 
$$n!!=n\times(n-2)\times(n-4)\times(...)\times3\times1$$
for odd numbers. But we're not limited to double factorials. For example
$$n!!!=n\times(n-3)\times(n-6)\times(...)\times6\times3$$
or
$$n!!!=n\times(n-3)\times(n-6)\times(...)\times5\times2$$
or
$$n!!!=n\times(n-3)\times(n-6)\times(...)\times4\times1$$
depending on the starting value.
In summary:
$${\displaystyle n!^{(k)}={\begin{cases}1&{\text{if }}n=0 \\n&{\text{if }}0<n\leq k\\n\cdot\left({(n-k)!}^{(k)}\right)&{\text{if }}n>k\end{cases}}}$$
where
$${\displaystyle n!^{(k)}=n\underbrace{!\dots!}\_{k}}$$
Or, in plain English: **Subtract the factorial count from the base number repeatedly and multiply all resulting positive integers.**
## The Challenge
Write a function that will calculate any kind of repeated factorial for any non-negative integer.
### Input
Either
* A string containing a non-negative base-ten integer, followed by 1 or more exclamation marks. E.g. `"6!"` or `"9!!"` or `"40!!!!!!!!!!!!!!!!!!!!"`.
or
* The same values represented by two integers: one non-negative base value and one positive value representing the factorial count. This can be done according to any format from the default I/O rules.
### Output
The result of said calculation.
## Challenge remarks
* `0!` equals `1` by definition. Your code must account for this.
* The factorial count is limited by $$ 0 < factorial~count \leq base~value $$outside this range, you are free to output whatever. Aside from `0!`, which is the only exception to this rule.
## Examples
```
Input                              Output
3!!!                               3
0!                                 1
6!                                 720
9!!                                945
10!!!!!!!!                         20
40!!!!!!!!!!!!!!!!!!!!             800
420!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  41697106428257280000000000000000
```
Try it with an ungolfed Python implementation: [Try it online!](https://tio.run/##bY5BCoMwEEX3/xQZNyZiRasULPQwImkrSAwxKe3p06mK7aJ/9XnzZhL78vfJ1FE/dS/bLEmSOBgrOBfBJXip8OjGoFfgJcNi9m6wMqVUKRghdrvop8DKZyAmJ5Y9OD2H0bNQAVemA5vCdeam5SLkZX4w6ozlzCZnfA6w7vPgihQi/03FmohQEk6ElltV0hY0e/0NmuNf/s0b "Python 3 – Try It Online")
## General remarks
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the answer using the fewest bytes in each language wins.
* [Standard rules](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/), [I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) and [loophole rules](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* Please include a [Try it Online](https://tio.run/#)-link to demonstrate your code working.
* Please motivate your answer with an explanation of your code.
  
[Answer]
# [R](https://www.r-project.org/), 33 bytes
```
function(n,k)prod(seq(n+!n,1,-k))
```
[Try it online!](https://tio.run/##LclJCoAwDEDRvaeouwQjdBDRhadRA1JIHc8fW3H1H/xTeVJ@ZL63JCAUcT/TAtd6gDS1kKM2IipDIBOwYrBkXGn/dyTjS10eQ0GX4e0nnxks6gs "R – Try It Online")
Handles \$n=0\$ by adding the logical negation of \$n\$. 
[Answer]
# [ArnoldC](https://lhartikk.github.io/ArnoldC/), 702 698 634 bytes
```
LISTEN TO ME VERY CAREFULLY f
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE n
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE p
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE r
YOU SET US UP 1
HEY CHRISTMAS TREE c
YOU SET US UP 0
STICK AROUND n
GET TO THE CHOPPER r
HERE IS MY INVITATION r
YOU'RE FIRED n
ENOUGH TALK
GET TO THE CHOPPER n
HERE IS MY INVITATION n
GET DOWN p
ENOUGH TALK
GET TO THE CHOPPER c
HERE IS MY INVITATION 0
LET OFF SOME STEAM BENNET n
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE c
GET TO THE CHOPPER n
HERE IS MY INVITATION 0
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
CHILL
I'LL BE BACK r
HASTA LA VISTA, BABY
```
[Try it online!](https://tio.run/##rZJBb9swDIXv@hXvlksPTlsM25GWaUuoLBqSnMDHIVtPRTZ02@/PqGYd0C3BtmZH0k8f6ff4/nH/6eHD7uDLKiM72RY/sjGOF1iXfC4jZZTEjMePX749fDWLzMhcMGfMExpjBi20mUBZlYKRUn4WdwJfEGWLe9zgxhQKd1VTHMNR7J51fw1psL4c8uZ/QN7h@nLIusHbyym3Da6b85iamKMNo2WOKJxGH6lwdwgab@0ombHhpJFT4n4OYcG98YjM3XEBG0Sx@Vi0IiWjTngqRymS7GIDY/@aR5/N4HW5KmVMLJP2yKeTJ/jL9a1PiXa/nWgu3t6Bksw6fv9k6w@frJNp4qRgx4nhM8YFPm58oeIlHgeu9EvvE9e3HGUeHKrXpzj7M5zj0E62UX/3D4zdGUZjgoql75FF89LoaNRIY9Tuy8VatjSrmX41YhAfhzoi0wK1lnJ16B9Wb16gf95SFCTOE9uCXhKCDN4a63wIxq9C0MXQkrquzlIuhEDYaEp0pe12ORy@Aw "ArnoldC – Try It Online")
Translated to pseudocode:
```
f(n,p) {
  r=1;
  c=0;
  while (n) {
    r=r*n;
    n=n-p;
    c=n<0;
    if (c) n=0;
  }
  return r;
}
```
Note: ArnoldC has only one type of data: 16-bit signed integer. Hence I cannot test the `420!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` case.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page)
```
RṚmP
```
[Try it online!](https://tio.run/##y0rNyan8/z/o4c5ZuQH///83MfhvZAAA "Jelly – Try It Online")
**How?** Given \$n\$ and \$k\$, it first generates the range \$n,\cdots, 1\$ (with `RṚ`), then with `m` it keeps every \$k^{\text{th}}\$ element of this range (so \$n, n-k, n-2k,\cdots,n-\lfloor n/k\rfloor k\$), and finally multiplies them using `P`.
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 7 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function. Takes `[n,b]` as argument.
```
×/-\…1¨
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn///B0fd2YRw3LDA@t@J/2qG3Co96@R31TPf0fdTUfWm/8qG0ikBcc5AwkQzw8g/@nKRgrGHOBSHMgaaBgCCTNwKSlghGQNDRQsABSJgYKRgYg2shAwdgAAA "APL (Dyalog Extended) – Try It Online")
`1¨` one for each element of the argument; `[1,1]`
`-\` cumulative difference; `[n,n-b]`
`…` range using second element of left argument as indicator of step, e.g. `[9,7]` continues with `5`
`×/` product
[Answer]
# [Haskell](https://www.haskell.org/), 21 bytes
```
n%a=product[n,n-a..1]
```
[Try it online!](https://tio.run/##HcVLDoMgEADQq8yiJpCMZoCmqQtPYlxM6M8UR4Ky8PKltJv3Xry97yGUIg0PMa237PdRUFruOjOVhWeBAWKaZYcTLBxBZfE5pQNUozWMyqHTqAhN9fK3R1s1hNfamdDSb0voSE/l4x@Bn1tpfYxf "Haskell – Try It Online")
Combining the built-in product function with stepped range enumeration beats what I could code up recursively (even with flawr saving a byte).
**22 bytes**
```
n%a|n<1=1|m<-n-a=n*m%a
```
[Try it online!](https://tio.run/##HcXNCgIhEADgV5lDgsYIo0a0sD5JdBikn6V1ELc9BPvsmXX5vgcvz@s8tyaKNxlddFserViOss@KW@ZJIEKpk7xgB5kL6FXSWusbtDIGzjpgMKgJXff4d0DfdYSn3oHQ029PGMhc2ifdZr4vzaZSvg "Haskell – Try It Online")
Here's a solution taking input in string format like `9!!`, which I think is more interesting.
**42 bytes**
```
(\[(n,a)]->product[n,n-length a..1]).reads
```
[Try it online!](https://tio.run/##bcFBCoAgEADAr2zRwSCloGt9JDssphbZJmrfb/tAMzvm04bAbtIs9CKow3aVc0z39piyUEcyWPJlB1RqWFuVLG6ZLzwIJojpoAINOKjHvvpR82tcQJ9Zmhg/ "Haskell – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 6 bytes
These are all equivalent 6-byters:
```
*F:Q1E
*F:E1Q
*F%E_S
```
[Try it online! (`*F:Q1E`)](https://pythtemp.herokuapp.com/?code=%2aF%3AQ1E&input=40%0A20&debug=0)
Or, **11 bytes**, taking input as a string:
```
*F:.vQ1/Q\!
```
[Test suite.](https://pythtemp.herokuapp.com/?code=%2aF%3A.vQ1%2FQ%5C%21&input=%2240%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%22&test_suite=1&test_suite_input=%223%22%0A%223%21%21%21%22%0A%223%21%21%21%21%21%21%21%22%0A%220%21%22%0A%226%21%22%0A%229%21%21%22%0A%2210%21%21%21%21%21%21%21%21%22%0A%2240%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%22%0A%22420%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%21%22&debug=0)
[Answer]
# JavaScript (ES6), 21 bytes
Takes input as `(k)(n)`.
```
k=>g=n=>n<1||n*g(n-k)
```
[Try it online!](https://tio.run/##ZcxBDoIwEAXQvadgOWOCtEOhJbHchSA0CmmJGFfcvRY1IZSf2b3/59G8m7l93qdXat2t8732g66Ntrq2V74s9mzApgP61tnZjd1ldAZ6yDEcJmuyLMlPe@UIbFN@1HJTSSxyQqg2r0QRuULg//fBj3OGIH4eWLHY89XpWwgueFlJzkpBigpJob6P/wA "JavaScript (Node.js) – Try It Online")
Or [**24 bytes**](https://tio.run/##bc1LDoIwEIDhvadg2ZognVLaYiyehSA0CpkaMV6/Dj4SQCfp6v86c6kf9djcztd7iuHUxs7F3lXeoavwAHgE3OPWM0x7HpuAYxja3RA861iOfHo8mSbLknyz7EBdzDr86XrWjRQrIUmUM1GqYiUsCfgeIfG7giJTH0HAirXIX0K@CQkFujQgtJJWFkbSh@XEJw) to support BigInts.
---
# JavaScript (ES6), 55 bytes
Takes input as a string, using the format described in the challenge.
```
s=>(a=s.split`!`,k=a.length-1,g=n=>n<1||n*g(n-k))(a[0])
```
[Try it online!](https://tio.run/##jc7dCoIwGMbx867CebSFH9v8huaNROAwNXNs0qQj790sImqG@D//Pe975Xeuy1vbD65U52qq2aRZDjnTnu5FOxSgcDrGPVHJZri4xGmYZLk8kHGU@wZKt0MI8iM@oalUUitReUI1sIZ2AACwEbLW830r2BkSb3AvSUwZb5UJxabNtrz7tFkYmZZg8G5tYrbLs@GHfmfOzDTFS0v/YmNmtiGJs4TgOKQpjRI6T/02PQA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 91 bytes
```
[S S S T    N
Push_1][S N
S _Duplicate_1][S N
S _Duplicate_1][T   N
T   T   _Read_STDIN_as_integer_(base)][T    T   T   _Retrieve_base][S S S N
_Push_0][T  N
T   T   _Read_STDIN_as_integer_(factorial)][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_base][S S S T  N
_Push_1][T  S S T   _Subtract][N
T   T   S N
_If_negative_jump_to_Label_PRINT_RESULT][S N
S _Duplicate_base][S T  S S T   S N
_Copy_0-based_2nd_(result)][T   S S N
_Multiply][S N
T   _Swap_top_two][S S S N
_Push_0][T  T   T   _Retrieve_factorial][T  S S T   _Subtract][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT_RESULT][S N
N
_Discard_top][T N
S T _Print_result_as_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
[Try it online](https://tio.run/##JYxRCoAwDEO/k1PkCGN6IZHB/BMUPH5tulLS5pH2m9c7nvs4R4QkUFQ2CFcSei2W4gBKsICNjFgqriu/ofOeaRCx98at/Q) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer result = 1
Integer base = STDIN as integer
Integer factorial = STDIN as integer
Start LOOP:
  If(base <= 0):
    Call function PRINT_RESULT
  result = result * base
  base = base - factorial
  Go to next iteration of LOOP
function PRINT_RESULT:
  Print result as integer to STDOUT
```
[Answer]
# [Python 2](https://docs.python.org/2/), 29 bytes
```
f=lambda n,b:n<1or n*f(n-b,b)
```
**[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIU8nySrPxjC/SCFPK00jTzdJJ0nzf0FRZl6JRpqGoZGOqabmfwA "Python 2 – Try It Online")**
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~10~~ ~~8~~ 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Ý¦RIιнP
```
Input as two separated inputs: first input being `base`; second input being `factorial`.
[Try it online](https://tio.run/##yy9OTMpM/f//8NxDy4I8z@28sDfg/38DLkMA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC6H8fA@@giHM7L@wN@K/zPzraWMc4VgdImgNJAx1DIGkGJi11jICkoYGOBZAyMdAxMgDRRgY6xgaxsQA).
-2 bytes thanks to *@Mr.Xcoder*.  
-1 byte thanks to *@JonathanAllan*.
**Explanation:**
```
Ý        # Create a list in the range [0, (implicit) base-input]
 ¦       # And remove the first item to make it the range [1, base]
         # (NOTE: this is for the edge case 0. For the other test cases simply `L` instead
         #  of `Ý¦` is enough.)
  R      # Reverse this list so the range is [base, 1]
   Iι    # Uninterleave with the second input as step-size
         #  i.e. base=3, factorial=7: [[3],[2],[1],[],[],[],[]]
         #  i.e. base=10, factorial=8: [[10,2],[9,1],[8],[7],[6],[5],[4],[3]]
         #  i.e. base=420, factorial=30: [[420,390,360,...,90,60,30],[419,389,359,...],...]
     н   # Only leave the first inner list
      P  # And take the product of its values
         # (which is output implicitly as result)
```
**Original 10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) answer:**
```
L0KD¤-IÖÏP
```
Input as two separated inputs: first input being `base`; second input being `factorial`.
[Try it online](https://tio.run/##yy9OTMpM/f/fx8DbxfPwtMP9Af//G3AZAgA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC6H8fA2@XQ0t0Iw5PO9wf8F/nf3S0sY5xrA6QNAeSBjqGQNIMTFrqGAFJQwMdCyBlYqBjZACijQx0jA1iYwE).
**Explanation:**
```
L           # Create a list in the range [1, (implicit) base-input]
 0K         # Remove all 0s (edge case for input 0, which will become the list [1,0])
   D        # Duplicate this list
    ¤       # Get the last value (without popping)
            # (could also be `Z` or `¹` for max_without_popping / first input respectively)
     -      # Subtract it from each item in the list
      IÖ    # Check for each if they're divisible by the second factorial-input
        Ï   # In the list we copied, only leave the values at the truthy indices
         P  # And take the product of those
            # (which is output implicitly as result)
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 22 bytes
```
{[*] $^a,*-$^b...^1>*}
```
[Try it online!](https://tio.run/##hc3RCoIwFIDh@z3FGUjoZnObc9OLepFKUFMINEOvRHz2ZRChUPnfnJvvnPMou1rbZoBdBQc7nsgFnDTzyd5Jc8ZYKo5kslXbgVvf7mXvwYgA@myAyqVNcL7SwH9NTANWtE3uocmGGGP4X4j4FgEQSG8jIzlKNv9BoiIkOH73k83H1EctW6mYz0x@dcsNJXRiBNdKxjIyct5a9wQ "Perl 6 – Try It Online")
Anonymous codeblock that returns the product of the range starting from the first input, decreasing by the second until it is below `1`, excluding the last number. This works for `0`, since the base case of a the reduce by product is 1, so the output is 1.
[Answer]
# x86-64 machine code, 12 bytes
Same machine code does the same thing in 32-bit mode, and for 16-bit integers in 16-bit mode.
This is a function, callable with args `n=RCX`, `k=ESI`. 32-bit return value in `EAX`.
Callable from C with the x86-64 System V calling convention with dummy args to get the real args into the right registers. `uint32_t factk(int, uint32_t k, int, uint64_t n);` I couldn't just use Windows x64 because 1-operand `mul` clobbers RDX, and we don't want REX prefixes to access R8/R9. `n` must not have any garbage in the high 32 bits so JRCXZ works, but other than that it's all 32-bit.
NASM listing (relative address, machine code, source)
```
 1                         factk:
 2 00000000 6A01             push 1
 3 00000002 58               pop rax             ; retval = 1
 4 00000003 E306             jrcxz  .n_zero      ; if (n==0) return
 5                         .loop:                ; do {
 6 00000005 F7E1              mul   ecx            ; retval *= n  (clobbering RDX)
 7 00000007 29F1              sub   ecx, esi       ; n -= k
 8 00000009 77FA              ja   .loop         ; }while(sub didn't wrap or give zero)
 9                         .n_zero:
10 0000000B C3               ret
```
0xc = 12 bytes
---
Or 10 bytes if we didn't need to handle the `n=0` special case, leaving out the `jrcxz`.
For standard factorial you'd use `loop` instead of sub/ja to save 2 bytes, but otherwise the exact same code.
---
Test caller that passes `argc` as `k`, with `n` hard-coded.
```
align 16
global _start
_start:
  mov  esi, [rsp]
;main:
  mov  ecx, 9
  call factk
  mov  esi, eax
  mov  edx, eax
  lea  rdi, [rel print_format]
  xor  eax, eax
extern printf
  call printf
extern exit
  call exit
section .rodata
print_format: db `%#x\t%u\n`
```
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 11 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit infix function. Takes `n` as right argument and `b` as left argument.
```
×/1⌈⊢,⊢-×∘⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT/////B0fcNHPR2PuhbpALHu4emPOmY86t38P@1R24RHvX2P@qZ6@j/qaj603vhR20QgLzjIGUiGeHgG/zdWSFMw5jIHk4ZA0gBMmnEZAUlLLgsgaWjAZWQApE0MuIzBtJEBAA "APL (Dyalog Unicode) – Try It Online")
`×∘⍳` multiply `b` by the **ɩ**ntegers 1 through `n`
`⊢-` subtract that from `n`
`⊢,` prepend `n`
`1⌈` max of one and each of those
`×/` product
[Answer]
# [Ruby](https://www.ruby-lang.org/), 25 bytes
```
f=->s,r{s<1?1:s*f[s-r,r]}
```
[Try it online!](https://tio.run/##hdDbCoJAEIDh@32KXehCS9fddT2F5oPYgQ4IQqXsKBjas9teRChU/tffzMCo5vQYhjyxN2CpDmKe8jUs8wxsZandc2iTOAbkEkLw/1zE5gjGHPnzKBAMRbP3cCQ9xBl595PpZfKjxk1UyDQTX914QnI/CjjzpQiFFwg9NQ0BqpoacEuhuha1sXBMejtWXa/6PFOZs99eVs6O1uWhsLCi57K510ZKTP3oFw "Ruby – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~22~~ 21 bytes
```
1##&@@Range[#,1,-#2]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE7876Zg@99QWVnNwSEoMS89NVpZx1BHV9koVu1/QFFmXkm0sq6dhpuDg7JmrJq@Q3W1sY5xrU61gY4hkDQDk5Y6RkDS0EDHAkiZGOgYGYBoIwMdY4Pa2v8A "Wolfram Language (Mathematica) – Try It Online")
-1 thanks to attinat: `Times --> 1##&`
Explanation: use `Range` to make a list of the values `{n, n-k, n-2k, n-3k, ...}`, stopping before going below 1 (i.e., stopping just right). Then multiply all numbers in this list with `Times` (or `1##&`).
[Answer]
# Java 10, 44 bytes
```
f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;}
```
Takes the factorial as first input, base as second.
[Try it online.](https://tio.run/##jZA9b4MwEIZ3fsWJCYohQKp@uTBWytApY9XBfDgyJQaZI1IU8dupIW4Jnbrd8/pO95wrdmJ@VXyNec26Dt6ZkBcLoEOGIodKvwY9ijrgvcxRNDJ4M8XrTmJ5KBX5X5Mp0hQ4JCP308xPL0IiqCSivFEOzdKQZn7CXXWXZFSV2CsJig4jtbRQ22e1FjJep0YUcNSuzh6VkIePT2Du5A2AZYfOlmxduuDjGiMSrvHhFmPyfItPJFp1xyG5/wk2m@s2HcXXbLCWz5sl54bpTs5ybJRg9U62PZIpylhXzmTU9@cOy2PQ9Bi0@iqspbOe8mxgsgDb@5307BeNPGBtW5//dLsmXdYYxWH8Bg)
This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use `BigIntegers`, which ~~coincidentally~~ is ~~exactly double the size - **88**~~ 79 bytes:
```
f->b->{var r=f.ONE;for(;b.signum()>0;b=b.subtract(f))r=r.multiply(b);return r;}
```
-9 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##nZE9a8MwEIb3/Iojk0UckY/SL9ceCi1kaDNkLB0kx3KVyrKRToYQ8ttdxTV1HDqUbnreu1fce7djNZvutp9Nqpi18MKkPowALDKUKex8lTqUigqnU5Slps/d46GtFQw/6KPMVxqzPDPhfx0XapKAgLgR04RPk0PNDJhY0PXrUyRKE0ScWplrVwQkmUU89ug4GpZiIAgxsaGFUygrtQ84iUyGzmgw0bGJRj5a5bjy0bqEdSm3UPjUwQaN1PnbOzBy2gAAZhaDZbgkUY83Q5yHsyFen@MivDvH23A@6F7MwquBsPTC4ls5jvojtCO2DVIjCB@zNJKpla4chieJM5u11A2@2VvMClo6pJXPhEoHQ9dkDExvYTz5cU7G9x4FZdVpa7@dhNZMuWwtLr4i5C@efkLSxTs2Xw)
**Explanation:**
```
f->b->{       // Method with two integer parameters and integer return-type
  int r=1;    //  Result-integer, starting at 1
  for(;b>0;   //  Loop as long as the base is still larger than 0
      b-=f)   //    After every iteration: decrease the base by the factorial
    r*=b;     //   Multiply the result by the base
  return r;}  //  Return the result
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
ɾṘḞΠ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwiyb7huZjhuJ7OoCIsIiIsIjMsIDNcbjMsIDdcbjAsIDFcbjYsIDFcbjksIDJcbjEwLCA4XG40MCwgMjBcbjQyMCwgMzAiXQ==)
[Answer]
# [Knight](https://github.com/knight-lang/knight-lang), ~~34~~ 33 bytes
```
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CYb@VYYSeWlq3ypeFyKv/L2SGxXfajp3A5H1f@KQ0VBNPnCW6/iEvagUiDeWs0HUAP5a4VEj2VDymSS0f9Cbl1U41sj2KVlceKGaWI@RtC4QWCe58SgjZjdNAXVWgtp6mAgnoflvz@Aapc7FBSIjlGmP2BJdyt4hF3y1YgY1fQk26QDWbGc1BeHLbfwshGGow0kvhC2IdsbSOzQ25DHG0jxLtiC/HFTZrjdzs8bSDF/b0GeV8iKNOURnA2qI/KZi91nJrvOXO4@g8V/65nD6oxGywxv/MfmsjjWbeTg6sVjtOts5qYlHct3jW0BsyVYo8rg43a1ApXSQ7@Z0tQsXuqOXel3GsI/VcKX2EetRvpaZC3xtpL5fS4C2r99QbcGi236/m/pkAhabbfhNJ5rBjYC6WdZy6p0RCGrlao2o3ZXKHCFivLQC6pc293UXIHLrMcB/5LqMF/WFcEhOtNrk3QXu3LdOv7Xkmtf8xEPOIhOWUVgdnnon0JPfH5@Pnt1@urZsuf24lq5teynW@vTecdeHC2UJ3veXijzG31@MP8/)
-1 byte thanks to Aiden Chow
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 bytes
```
TõUV f ×
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=VPVVViBmINc&input=MCwx)
-1 thanks to EoI pointing out how dumb uncaffeinated Shaggy can be!
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 41 bytes
```
r;f(n,k){for(r=1;n>0;n-=k)r*=n;return r;}
```
[Try it online!](https://tio.run/##ZcnBCkBAEADQM1@xKTWjVUsumtaXuGhZSYamdZJvX5y963Pl7FyMQh5Yr3j5XUBsRdwZ4tKuKIVlkimcwkrojtuwMKC60uSQhYOHLB97zrSHxmhVG0T6V/vOF3d8AA "C (gcc) – Try It Online")
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), ~~7~~ 6 bytes
```
╙╒x%ε*
```
[Try it online!](https://tio.run/##y00syUjPz0n7///R1JmPpk6qUD23Vev/f2MFYy4LIDZUMABiMy4jBUsg39CAy8hAwcSAyxhIGhn8BwA "MathGolf – Try It Online")
Found a clever way to handle 0! without changing the other test cases. Takes input as `k n` (reverse order), which helps with implicit popping.
## Explanation
```
╙        maximum of two elements (pops largest of k and n,
         which is n for every valid case except 0!, where 1 is pushed)
 ╒       range(1,n+1)
  x      reverse int/array/string
   %     slice every k:th element
    ε*   reduce list with multiplication
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), ~~21~~ 19 bytes
```
${x<y∨x*$[x-y,y]}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@1@lusKm8lHHigotlegK3Uqdytja/36pqSnF0SoFBcnpsVwBRZl5JSGpxSXOicWpxdFqaToK0VwKQGBvrxBtrKNgEKsD5oLYxlA2VMocJmWgo2AIY5shsS11FIxgbEOgIgsYxwTIMYKbbGIE5BobxHLFxv4HAA "Attache – Try It Online") Pretty direct recursive implementation. (Note: `true` is essentially `1`, as it can be used in arithmetic operations as `1`.) This is one of the few programs I've written for this site where using a unicode operator saves bytes (1, to be precise).
## Alternatives
**20 bytes:** `${x<y or x*$[x-y,y]}`
**21 bytes:** `Prod@${{_%y=x%y}\1:x}`
**27 bytes:** `${x*[`1,$][x>y][x-y,y]∨1}`
**27 bytes:** `${If[x>y,x*$[x-y,y],_or 1]}`
**27 bytes:** `${x*[`1,$][x>y][x-y,y]or 1}`
**29 bytes:** `${If[x>y,x*$[x-y,y],_+not _]}`
[Answer]
# [Scala](http://www.scala-lang.org/), 53 bytes
Takes two arguments, the first being the number and the second being the `!` count.
  
Somehow breaks on the big test case. This step range costs many bytes in the end because of this `-1*` so improvements ought to be possible by refactoring.
  
I have, as always, a doubt about how we count bytes for function declarations, because everyone doesn't do the same way everywhere down there, so well... It's **17 bytes less**, so **36 bytes**, if we count out func variables' (`a` and `b`) declaration and func brackets.
```
(a:Int,b:Int)=>{var s=1
for(i<-a to b by -1*b)s*=i
s}
```
[Try it online!](https://tio.run/##jZBPb4MgHIbvfIqfnrSlKSD1TzOW7LjDPgRUzFgMGrHNlqafnblsdRo99D1wep73BdxJ1tI36kOfeniTxoL@7LUtHby07RWhUldQCR/J46vtsfo5Y/F8vcgOnKCoarrIPO0k9A0oUF@woxsVu40wyN082u/bzti@tlGYgIBwW0UJJvE2BGlLcO/NuS5BaTjbYcdYXYYx@jeCIBilZCklAzwdCH4zKtmDO@SuEEyXCp2i6R1N19CMkSlcjHcpMFvSBT9MaUqC@QMowfnSmk/wUZrmr4ATzFb@OifzCrbasWxjBCcrdZymRUZJylnODhkb2ucZttDNe/8N "Scala – Try It Online") I commented out the broken test cases, because, well, they do break.
[Answer]
# [Rust](https://www.rust-lang.org/), ~~92~~ ~~73~~ 61 bytes
```
fn f(n:i128,k:i128)->i128{if n<=0{return 1}return n*f(n-k,k)}
```
I am just starting to learn rust, so I'm sure this can be shorter. Will update as I learn. The return value should be `i128` in order to compute the last test.
Edit: Recursion is shorter.
[Try it online!](https://tio.run/##dYxLDgIhEET3fQqcFZiepAFjxu9dXEhC0I5hmBXh7IgTd@KqKu@lKi5zqtWxcJKPXpsJwxpqvH4ieyf4fKEc72mJLHT5Ft62wRgwqAIAbf@8eZYKMryi5/TgjRxyGbD9WrRKnX45oe7y/R9@QNPlmnDqih2hob4xhHZVpdY3 "Rust – Try It Online")
You can add your own test, or edit one of the already existing ones.
[Answer]
## **[q](https://code.kx.com/v2/ref/), ~~59 57 55~~ 53 bytes**
```
{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x}
```
explanation:
```
q)x:"12!!" / let our input be 12!!, assign to x
q)sum n:"!"=x / count "!"s
2i
q)(!)sum n:"!"=x / (!)m -> [0,m)
0 1
q)("J"$x(&)not[n]) / isolate the number in input
12
q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around
0 1 0 1 0 1 0 1 0 1 0 1
q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i
q)i
0 1 0 1 0 1 0 1 0 1 0 1
q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i
010101010101b
q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem
10101010101b
q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE)
0 2 4 6 8 10
q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array
2 4 6 8 10 12
q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array
46080
```
here also is a version in k (same logic), ~~42~~41 bytes
```
{*/2+&1_i=last i:("J"$x@&~:n)#!+/n:"!"=x}
```
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, ~~30~~ ~~29~~ 24 bytes
* Saved 1 byte thanks to @Bubbler
* Saved 5 bytes thanks to @chunes!
```
[ 1 rot neg <range> Π ]
```
[Try it online!](https://tio.run/##LY47DsIwEER7TjEniBKQED/RIhoaRBWlsJxNiDB2WG8KFHIXTsSVjAkpdt7sSKvZSmlxHC7n4@mwwY3YkkHLJPJsubECT4@OrCYP47QyHncl11ESVramf5B0ttGuJGxnPXosMMcQmU5cIhu5nvYsxSqaAfkLBr/xpJ0to6ka9hLyeMBOYKnGbuzZ4/NGEeILBkXsbJGELw "Factor – Try It Online")
Takes `k` (which -th factorial) and then `n`. First we push an `n` onto the stack, then `rot` makes the stack look like `n 1 k`. `neg` negates `k`, which will act as the step for a range from `n` to 1 (made using `<range>`). Then `Π` finds the product of that range, and that's it.
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 3.5 bytes (7 nibbles)
```
`*`%@\,
```
```
      ,         # get the range from 1..first input,
     \          # reverse it,
   %            # and take each element in steps of
    @           # the second input,
`*              # and finally get the product
```
[![enter image description here](https://i.stack.imgur.com/5oXRZ.png)](https://i.stack.imgur.com/5oXRZ.png)
---
Or **7.5 bytes (15 nibbles)** with input as string of a base-ten integer followed by exclamation marks:
```
`*`%,|$\$D\,`r$
```
[![enter image description here](https://i.stack.imgur.com/Igyzn.png)](https://i.stack.imgur.com/Igyzn.png)
[Answer]
# [Physica](https://github.com/Mr-Xcoder/Physica), 22 bytes
```
f=>n;k:n<1||n*f[n-k;k]
```
[Try it online!](https://tio.run/##K8ioLM5MTvz/P83WLs862yrPxrCmJk8rLTpPN9s6O/a/W36RQklqcYmCZ55CdbWxtXGtNZA0B5IG1oZA0gxMWlobAUlDA2sLIGViYG1kAKKNDKyNDWprrbg4A4oy80oc0qK1QEbF/gcA "Physica – Try It Online")
---
**26 bytes**
Re-learning how to use my own "language" \o/... If I knew how to write a parser 2 years ago, this would have been 20 bytes :(
```
->n;k:GenMul##[n…1]{%%k}
```
or
```
->n;k:GenMul##Range[n;1;k]
```
[Try it online!](https://tio.run/##K8ioLM5MTvyfpmCrEPNf1y7POtvKPTXPtzRHWTk671HDMsPYalXV7Nr/bvlFCiWpxSUKnnkK1dXG1sa11kDSHEgaWBsCSTMwaWltBCQNDawtgJSJgbWRAYg2MrA2NqitteLiDCjKzCtxSIvWAhkV@x8A "Physica – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 66 bytes
```
^0
1
\d+
*!,
+`(!+)(!+),\1$
$1$2,$2,$1
!+$
1
+`(!+),(\d+)
$.($2*$1
```
[Try it online!](https://tio.run/##TUoxCoAwENvzi8AJ1RbpqQi@wE@IKOjg4iD@v7aKYkhCSHKs57bPGjLTT2H0UAyLRUEHOxnaPMkNKhCVyiUqaCX@nt2Z@M8hpZGqEA2hRk3ytgR4oiW6mNTzLZsv/nEB "Retina – Try It Online") Link includes faster test cases. Mauls numbers without exclamation marks. Explanation:
```
^0
1
```
Fix up `0!`.
```
\d+
*!,
```
Convert `n` to unary and add a separator.
```
+`(!+)(!+),\1$
$1$2,$2,$1
```
Repeatedly subtract `k` from `n` while `n>k`, and collect the results.
```
!+$
1
```
Replace `k` with `1` (in decimal).
```
+`(!+),(\d+)
$.($2*$1
```
Multiply by each intermediate value in turn, converting to decimal.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 bytes
```
1õUV f ×
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=MfVVViBmINc&input=MTAKOA)
]