# Sequential Multiplication

Your objective is to write a program that takes an input, and, when chained together N times, performs "sequential multiplication". What is sequential multiplication, you may ask? It's a sequence with a seed a defined as thus:

f(0) = a
f(n+1) = f(n)*(f(n)-1)

So, let a = 5. Thus, f(0) = 5, f(1) = f(0)*(f(0)-1) = 5*4 = 20, and f(2) = f(1)*(f(1)-1) = 20*19 = 380.

If your program was ABC, then ABC should take input a and output f(1). Program ABCABC should output f(2), etc. Your program series should only take input once and only output once.

This is a code-golf so the shortest program in bytes wins. Standard loopholes are banned.

# Jelly, 3 bytes

×’$Try it online! ### How it works ×’$    Main link (or part thereof). Argument (initially input): n

’     Compute n - 1.
×      Multiply n by (n - 1).

### Alternate version, 10 bytes

$_*=~-$_;

This requires the -p switch. I'm not sure if it is fair game in a question.

(*)=<<pred$Usage example Prelude> (*)=<<pred$5
20
Prelude> (*)=<<pred$(*)=<<pred$5
380
Prelude> (*)=<<pred$(*)=<<pred$(*)=<<pred$5 144020 Maybe this isn't a proper function. If you're nitpicking you can go with (*)=<<pred$id (<-there's a space at the end) for 14 bytes.

Edit: @Zgarb rewrote the function using the function monad and saved 3 bytes. Thanks!

# Explanation:

Unary is always odd, so the first application will convert to decimal. x*(x-1) is always even, so otherwise it returns x*(x-1), where x is the input. Because Haskell is strongly typed and 'special' symbols cannot be called like &1, I believe that this is pretty much the only way to complete this in Haskell, unless one used global variables or an even odder input form.

# C++ (gcc), 173 / 176 bytes

Both versions have a crucial newline at the end.

## Macro version, 173 bytes

#ifndef M
#define M(a,b)a##b
#define W(z,x)M(z,x)
#define B int W(m,__LINE__)=x++
#include<iostream>
int x,n;int main(){for(std::cin>>n;x--;)n*=n-1;std::cout<<n;}
#endif
B;

Try it online!

## Template version, 176 bytes

Somewhat more C++ish:

#ifndef B
#define B template
#include<iostream>
int x,n;B<int N>struct A{static int i;};int main(){for(std::cin>>n;x--;)n*=n-1;std::cout<<n;}
#endif
B<>int A<__LINE__>::i=x++;

Try it online!

## Burlesque - 5 bytes

J?d?*

blsq ) 5 J?d?*
20
blsq ) 5 J?d?* J?d?*
380
blsq ) 5 J?d?* J?d?* J?d?*
144020