Given a number N, the task is to find the number of pairs containing an even and an odd number from numbers between 1 and N inclusive.
Note:Order of numbers in the pair does not matter that is (1, 2) and (2, 1) are the same.
Input: N = 3 Output: 2 The pairs are (1, 2) and (2, 3). Input: N = 6 Output: 9 The pairs are (1, 2), (1, 4), (1, 6), (2, 3), (2, 5), (3, 4), (3, 6), (4, 5), (5, 6).
Approach: Number of ways to form the pairs is (Total number of Even numbers*Total number of Odd numbers).
- if N is even number of even numbers = number of odd numbers = N/2
- if N is odd number of even numbers = N/2 and number of odd numbers = N/2+1
Below is the implementation of the above approach:
- Number of ways to split a binary number such that every part is divisible by 2
- Count number of ways to divide a number in 4 parts
- Find the number of ways to divide number into four parts such that a = c and b = d
- Ways to choose balls such that at least one ball is chosen
- Number of ways to get a given sum with n number of m-faced dices
- Number of indices pair such that element pair sum from first Array is greater than second Array
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Count number of ways to get Odd Sum
- Number of ways of writing N as a sum of 4 squares
- Total number of ways to place X and Y at n places such that no two X are together
- Bell Numbers (Number of ways to Partition a Set)
- Number of ways to distribute N Paper Set among M students
- Number of ways in which N can be represented as the sum of two positive integers
- Count number of ways to arrange first N numbers
- Ways to express a number as product of two different factors
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.