Program to find all possible triangles having same Area and Perimeter | C ++ program for the above approach ; Function to print sides of all the triangles having same perimeter & area ; Stores unique sides of triangles ; i + j + k values cannot exceed 256 ; Find the value of 2 * s ; Find the value of 2 * ( s - a ) ; Find the value of 2 * ( s - b ) ; Find the value of 2 * ( s - c ) ; If triplets have same area and perimeter ; Store sides of triangle ; Sort the triplets ; Inserting in set to avoid duplicate sides ; Print sides of all desired triangles ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void samePerimeterAndArea ( ) { set < vector < int > > se ; for ( int i = 1 ; i <= 256 ; ++ i ) { for ( int j = 1 ; j <= 256 ; ++ j ) { for ( int k = 1 ; k <= 256 ; ++ k ) { int peri = i + j + k ; int mul1 = - i + j + k ; int mul2 = i - j + k ; int mul3 = i + j - k ; if ( 16 * peri == mul1 * mul2 * mul3 ) { vector < int > v = { i , j , k } ; sort ( v . begin ( ) , v . end ( ) ) ; se . insert ( v ) ; } } } } for ( auto it : se ) { cout << it [ 0 ] << " ▁ " << it [ 1 ] << " ▁ " << it [ 2 ] << endl ; } } int main ( ) { samePerimeterAndArea ( ) ; return 0 ; }