B - tcaF
Source: atcoder
Difficulty: 150

Problem Statement
You are given an integer
X
not less than
2
.
Find the positive integer
N
such that
N! = X
.
Here,
N!
denotes the factorial of
N
, and it is guaranteed that there is exactly one such
N
.
Constraints
2 \leq X \leq 3 \times 10^{18}
There is exactly one positive integer
N
such that
N!=X
.
All input values are integers.
Input
The input is given from Standard Input in the following format:
X
Output
Print the answer.
Sample Input 1
6
Sample Output 1
3
From
3!=3\times2\times1=6
, print
3
.
Sample Input 2
2432902008176640000
Sample Output 2
20
From
20!=2432902008176640000
, print
20
.

C++ solution:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 1; i < (long long)(n); i++)
using namespace std;

int main() {
  long long x;
  long long count = 1;
  cin >>x;
  rep(i,21){
    count *= i;
    if(count == x) cout << i << endl;
  }
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	buf = bufio.NewReader(os.Stdin)
)

func solve() {
	line, _ := buf.ReadString('\n')
	params := strings.Split(strings.TrimSpace(line), " ")
	x, _ := strconv.ParseInt(params[0], 10, 64)
	var p int64 = 1
	for i := 1; ; i++ {
		p *= int64(i)
		if p == x {
			fmt.Println(i)
			return
		}
	}
}

func main() {
	var T int = 1
	// line, _ := buf.ReadString('\n')
	// params := strings.Split(strings.TrimSpace(line), " ")
	// T, _ = strconv.Atoi(params[0])
	for i := 0; i < T; i++ {
		solve()
	}
}

func swap(x, y *int) {
	z := *x
	*x = *y
	*y = z
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int64) int64 {
	return x / gcd(x, y) * y
}

Java solution:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long n = 2;
        while (true) {
            long fact = factorial(n);
            if (fact == x) {
                System.out.println(n);
                break;
            } else if (fact > x) {
                System.out.println("No solution found");
                break;
            }
            n++;
        }
    }

    public static long factorial(long n) {
        long result = 1;
        for (long i = 2; i <= n; i++) {
            result *= i;
        }
        return result;
    }
}

JavaScript solution:
function Main(input) {
	const inp = input.split("\n"); 
	var X=Number(inp[0])
	var N=0;
	for(var j=0;j<100;j++){
	N++
	var N_k=1;
	for(var i=1;i<=N;i++){
	  N_k=N_k*i
	}
	if(N_k==X){
	  console.log(N)
	  break;
	}
	}
  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Python solution:
x = int(input())
f = True
fact = 1
cur = 1
while f:
  if fact == x:
    print(cur-1)
    f = False
  fact = cur * fact
  cur += 1

Ruby solution:
MEMO = {}
def factorial(n)
  return 1 if n <= 0
  return MEMO[n] if MEMO[n]
  MEMO[n] = n * factorial(n-1)
  return MEMO[n]
end

x = gets.to_i
i = 1
cur = i
while x > cur do
  cur = factorial(i)
  i += 1
end
puts i-1