Easy

Given an integer n, find the minimal k such that

  • k = m! (where m! = 1 * 2 * ... * m) for some integer m;
  • k >= n.

In other words, find the smallest factorial which is not less than n.

Example

For n = 17, the output should be
leastFactorial(n) = 24.

17 < 24 = 4! = 1 * 2 * 3 * 4, while 3! = 1 * 2 * 3 = 6 < 17).

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    A positive integer.

    Guaranteed constraints:
    1 ≤ n ≤ 120.

  • [output] integer

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int leastFactorial(int n)
{
	int factorial=1;

	for(int i=1;factorial<n;i++)
		factorial*=i;

	return factorial;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Magical Well  (0) 2020.04.12
<Codesignal> Count Sum of Two Representations 2  (0) 2020.04.12
<Codesignal> Second-Rightmost Zero Bit  (0) 2020.04.12
<Codesignal> Mirror Bits  (0) 2020.04.09
<Codesignal> Range Bit Count  (0) 2020.04.07

+ Recent posts