Given an integer N, we need to find three integers(X, Y, Z) which can form a triangle with the following conditions:
- Lengths of sides are integers not exceeding N.
- XOR of three sides is 0, i.e., X ^ Y ^ Z = 0
- Area of triangle is greater than 0.
Find all the possible triples which satisfy the above conditions.
Input: 6 Output: 6 5 3 Input: 10 Output: 10 9 3 6 5 3
Naive Approach: Select the first side by iterating from N to 1 and then select the second side by iterating from the first side to 1 and then select third side by iterating from second side to 1. Now check if the three sides can make a triangle(sum of the two smaller sides must be greater than the longest side) and the xor-sum of lengths is equal to 0.
Time Compelxity = O(n^3).
Efficient Approach: In this method we select the first two sides as we did in the first approach, the third side will be equal to the xor of the first two sides(this will make the xor-sum of lengths is equal to 0)and this side must be smaller than the first two sides. Now check if these sides can make a triangle.
Time Complexity = O(n^2)
10 9 3 6 5 3
- Count right angled triangles in a matrix having two of its sides parallel to sides of the matrix
- Count number of triangles possible for the given sides range
- Count number of triangles possible with length of sides not exceeding N
- Area of the circumcircle of any triangles with sides given
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Print all the Paths of a Binary Tree whose XOR is non-zero
- Find array such that no subarray has xor zero or Y
- Check if it is possible to create a polygon with given n sides
- Count the number of possible triangles
- Number of possible Triangles in a Cartesian coordinate system
- Number of triangles possible with given lengths of sticks which are powers of 2
- Count of Equilateral Triangles of unit length possible from a given Hexagon
- Given a set, find XOR of the XOR's of all subsets.
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Ways to remove one element from a binary string so that XOR becomes zero
- Minimum operations to make XOR of array zero
- Number of unique triplets whose XOR is zero
- Maximize the number of subarrays with XOR as zero
- Check if a number from every row can be selected such that xor of the numbers is greater than zero
- Quadruplet pair with XOR zero in the given Array
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.
Improved By : vt_m