Find unique pairs such that each element is less than or equal to N | Finding the number of unique pairs ; Using the derived formula ; Printing the unique pairs ; Driver Code
< ? php function No_Of_Pairs ( $ N ) { $ i = 1 ; while ( ( $ i * $ i * $ i ) + ( 2 * $ i * $ i ) + $ i <= $ N ) $ i ++ ; return ( $ i - 1 ) ; } function print_pairs ( $ pairs ) { $ i = 1 ; $ mul ; for ( $ i = 1 ; $ i <= $ pairs ; $ i ++ ) { $ mul = $ i * ( $ i + 1 ) ; echo " Pair ▁ no . " , $ i , " ▁ - - > ▁ ( " , ( $ mul * $ i ) , " , ▁ " , $ mul * ( $ i + 1 ) , " ) ▁ STRNEWLINE " ; } } $ N = 500 ; $ pairs ; $ mul ; $ i = 1 ; $ pairs = No_Of_Pairs ( $ N ) ; echo " No . ▁ of ▁ pairs ▁ = ▁ " , $ pairs , " ▁ STRNEWLINE " ; print_pairs ( $ pairs ) ; ? >