
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if product of first N natural numbers is divisible by their sum in Python
Suppose we have a number n. We have to check whether the product of (1*2*...*n) is divisible by (1+2+...+n) or not
So, if the input is like num = 5, then the output will be True as (1*2*3*4*5) = 120 and (1+2+3+4+5) = 15, and 120 is divisible by 15.
To solve this, we will follow these steps −
- if num + 1 is prime, then
- return false
- return true
Example
Let us see the following implementation to get better understanding −
def isPrime(num): if num > 1: for i in range(2, num): if num % i == 0: return False return True return False def solve(num): if isPrime(num + 1): return False return True num = 3 print(solve(num))
Input
5
Output
True
- Related Articles
- Sum of first N natural numbers which are divisible by X or Y
- Sum of first N natural numbers which are divisible by 2 and 7 in C++
- Number of pairs from the first N natural numbers whose sum is divisible by K in C++
- Count pairs of numbers from 1 to N with Product divisible by their Sum in C++
- Find if given number is sum of first n natural numbers in C++
- Python Program for cube sum of first n natural numbers
- Sum of sum of first n natural numbers in C++
- Python Program for Sum of squares of first n natural numbers
- Sum of first n natural numbers in C Program
- Sum of square-sums of first n natural numbers
- Sum of all subsets of a set formed by first n natural numbers
- Find the sum of first $n$ odd natural numbers.
- Finding sum of first n natural numbers in PL/SQL
- Sum of squares of first n natural numbers in C Program?
- Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python

Advertisements