

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the number of ways to divide number into four parts such that a = c and b = d in C++
Suppose we have a number n. We have to find number of ways to divide a number into parts (a, b, c and d) such that a = c, and b = d. So if the number is 20, then output will be 4. As [1, 1, 9, 9], [2, 2, 8, 8], [3, 3, 7, 7] and [4, 4, 6, 6]
So if N is odd, then answer will be 0. If the number is divisible by 4, then answer will be n/4 – 1 otherwise n/4.
Example
#include <iostream> using namespace std; int countPossiblity(int num) { if (num % 2 == 1) return 0; else if (num % 4 == 0) return num / 4 - 1; else return num / 4; } int main() { int n = 20; cout << "Number of possibilities: " << countPossiblity(n); }
Output
Number of possibilities: 4
- Related Questions & Answers
- Find four elements a, b, c and d in an array such that a+b = c+d in C++
- Count number of ways to divide a number in parts in C++
- Divide a number into two parts in C++ Program
- Find largest d in array such that a + b + c = d in C++
- Divide a big number into two parts that differ by k in C++ Program
- Find count of digits in a number that divide the number in C++
- All ways to divide array of strings into parts in JavaScript
- Divide number into two parts divisible by given numbers in C++ Program
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome
- Possible cuts of a number such that maximum parts are divisible by 3 in C++
- How to divide an unknown integer into a given number of even parts using JavaScript?
- C++ Partition a Number into Two Divisible Parts
- Count the number of rectangles such that ratio of sides lies in the range [a,b] in C++.
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1<=a<=b<=c<= n in C++
Advertisements