- Related Questions & Answers
- Find the first natural number whose factorial is divisible by x in C++
- PHP program to find the sum of first n natural numbers that are divisible by a number ‘x’ or a number ‘y’
- PHP program to find the sum of the first n natural numbers who are not powers of a specific number ‘k’
- C++ program to find first digit in factorial of a number
- 8085 program to find the factorial of a number
- 8086 program to find the factorial of a number
- Find minimum number to be divided to make a number a perfect square in C++
- Program to find remainder when large number is divided by 11 in C++
- Program to find remainder when large number is divided by r in C++
- PHP program to find the first ‘n’ numbers that are missing in an array
- C++ Program to Find Factorial of a Number using Iteration
- C++ Program to Find Factorial of a Number using Recursion
- Java program to find the factorial of a given number using recursion
- C++ Program to Find Factorial of a Number using Dynamic Programming
- How to Find the Factorial of a Number using Python?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To find the first natural number whose factorial can be divided by a number ‘x’, the code is as follows −

<?php function factorial_num($x_val) { $i = 1; $fact_num = 4; for ($i = 1; $i < $x_val; $i++) { $fact_num = $fact_num * $i; if ($fact_num % $x_val == 0) break; } return $i; } $x_val = 16; print_r("The first natural number whose factorial can be divided by 16 is "); echo(factorial_num($x_val)); ?>

The first natural number whose factorial can be divided by 16 is 4

A function named ‘factorial_num’ computes factorial of a number and checks to see if it is divisible by 16, and if yes, returns that number as output. Outside the function, a number is defined and it is passed as parameter to the function. Relevant output is displayed on the console.

Advertisements