Find maximum among x^(y^2) or y^(x^2) where x and y are given
Given X and Y whose values are greater than 2, the task is to find out which is maximum among
x^(y^2) and y^(x^2)
Consider that either x is greater than y or y is greater than x. So, print 1 if x^(y^2) is greater or 2 if y^(x^2) is greater.
Examples:
Input: X = 4, Y = 9 Output: 1 Input: X = 4, Y = 3 Output: 2
Approach: Assume
*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
, then after taking ln on both sides and dividing by
*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
we can get
*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
.
Take
*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
. This function is monotonically decreasing for
*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
.

If x > y, then F(x) < F(y)
C++
// C++ program to find the greater value#include <bits/stdc++.h>using namespace std;// Function to find maximumbool findGreater(int x, int y){ // Case 1 if (x > y) { return false; } // Case 2 else { return true; }}// Driver Codeint main(){ int x = 4; int y = 9; findGreater(x, y) ? cout << "1\n" : cout << "2\n"; return 0;} |
Java
// Java program to find// the greater valueimport java.io.*;class GFG{// Function to find maximumstatic boolean findGreater(int x, int y){ // Case 1 if (x > y) { return false; } // Case 2 else { return true; }}// Driver Codepublic static void main (String[] args){ int x = 4; int y = 9; if(findGreater(x, y)) System.out.println("1"); else System.out.println("2");}}// This code is contributed// by inder_verma. |
Python3
# Python3 program to find# the greater value# Function to find maximumdef findGreater(x, y): # Case 1 if (x > y): return False; # Case 2 else: return True;# Driver Codex = 4;y = 9;if(findGreater(x, y)): print("1");else: print("2");# This code is contributed# by mits |
C#
// C# program to find// the greater valueusing System;class GFG{// Function to find maximumstatic bool findGreater(int x, int y){ // Case 1 if (x > y) { return false; } // Case 2 else { return true; }}// Driver Codepublic static void Main (){ int x = 4; int y = 9; if(findGreater(x, y)) Console.WriteLine("1"); else Console.WriteLine("2");}}// This code is contributed// by inder_verma. |
PHP
<?php// PHP program to find the greater value// Function to find maximumfunction findGreater($x, $y){ // Case 1 if ($x > $y) { return false; } // Case 2 else { return true; }}// Driver Code$x = 4;$y = 9;if(findGreater($x, $y) == true) echo("1\n");else echo("2\n");// This code is contributed// by inder_verma?> |
Javascript
<script>// JavaScript program to find// the greater value// Function to find maximumfunction findGreater(x,y){ // Case 1 if (x > y) { return false; } // Case 2 else { return true; }}// Driver Codevar x = 4;var y = 9;if(findGreater(x, y))document.write("1");elsedocument.write("2");// This code is contributed by 29AjayKumar</script> |
1
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.



