- 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

Suppose, there are several cubes of dimensions a, b, and c, and using them a new box of dimension axbxc is created. a, b, and c are pairwise co-prime; gcd(a, b) = gcd(b,c) = gcd(c, d) = 1. We have to cut the box into two pieces with a single slice as shown in the picture. We have to find out if the box is cut this way, how many cubes are cut into two pieces. We are provided an array that contains the possible three dimensions, and we have to find out our answer from that.

The cut is done in this way that it is plane going through the vertices P, Q, and R.

So, if the input is like n = 3, input_array = [[1, 2, 3], [4, 2, 5], [6, 8, 2]], then the output will be [5, 18, 37]

There are 3 different instances given and we have to find out the number of cubes cut. If the cubes are cut in the way shown in the picture; 5, 16, and 37 cubes are cut respectively.

To solve this, we will follow these steps &miuns;

- output := a new list
- for i in range 0 to n, do
- a := input_array[i, 0]
- b := input_array[i, 1]
- c := input_array[i, 2]
- val := floor value of (a * b + a * c + b * c - 1) / 2 mod 1000000007
- insert val at the end of output

- return output

Let us see the following implementation to get better understanding −

from math import ceil def solve(n, input_array): output = [] for i in range(n): a, b, c = input_array[i][0], input_array[i][1], input_array[i][2] val = ((a * b + a * c + b * c - 1) // 2 % 1000000007) output.append(val) return output print(solve(3, [[1, 2, 3], [4, 2, 5], [6, 8, 2]]))

3, [[1, 2, 3], [4, 2, 5], [6, 8, 2]]

[5, 18, 37]

- Related Questions & Answers
- Program to find out how many transfer requests can be satisfied in Python
- Program to find out how many boxes can be put into the godown in Python
- Python Program to find out how many times the balls will collide in a circular tube
- Program to find how many lines intersect in Python
- Program to count how many ways we can cut the matrix into k pieces in python
- Program to find in which interval how many tasks are worked on in Python
- Program to find minimum cost to cut a stick in Python
- PHP program to find the sum of cubes of natural numbers that are odd
- Program to find out if two expression trees are equivalent using Python
- Program to Find Out Currency Arbitrage in Python
- Program to find how many ways we can climb stairs in Python
- C++ Program to find out how many movies an attendee can watch entirely at a Film festival
- Program to find how many distinct rotation groups are there for a list of words in Python
- Program to find how many swaps needed to sort an array in Python
- Program to find intervals that do not intersect the cut interval in Python

Advertisements