📌  相关文章
📜  在给出x和y的x ^(y ^ 2)或y ^(x ^ 2)中找到最大值

📅  最后修改于: 2021-04-24 17:58:37             🧑  作者: Mango

给定X和Y的值大于2,任务是找出其中最大的X和Y

考虑x大于yy大于x 。因此,如果x ^(y ^ 2)较大,则打印1;如果y ^(x ^ 2)较大,则打印2

例子:

Input: X = 4, Y = 9
Output: 1

Input: X = 4, Y = 3
Output: 2

方法:假设x^y^2 > y^x^2 ,然后在两边取ln并除以(xy)^2我们可以得到ln(x)/(x^2) > ln(y)/(y^2)

F(x) = ln(x)/(x^2) 。该函数单调递减x > 2

If x > y, then F(x) < F(y)
C++
// C++ program to find the greater value
#include 
using namespace std;
  
// Function to find maximum
bool findGreater(int x, int y)
{
    // Case 1
    if (x > y) {
       return false;
    }
  
    // Case 2
    else {
        return true;
    }
}
  
// Driver Code
int 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 value
import java.io.*;
  
class GFG 
{
  
// Function to find maximum
static boolean findGreater(int x,   
                           int y)
{
    // Case 1
    if (x > y)
    {
        return false;
    }
  
    // Case 2
    else 
    {
        return true;
    }
}
  
// Driver Code
public 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 maximum
def 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)):
    print("1");
else:
    print("2");
  
# This code is contributed
# by mits


C#
// C# program to find
// the greater value
using System;
  
class GFG 
{
  
// Function to find maximum
static bool findGreater(int x, 
                        int y)
{
    // Case 1
    if (x > y)
    {
        return false;
    }
  
    // Case 2
    else
    {
        return true;
    }
}
  
// Driver Code
public 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
 $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
?>


输出:
1