📜  前N个自然数的所有对(i,j)中的最大LCM

📅  最后修改于: 2021-05-07 05:09:54             🧑  作者: Mango

给定正整数N> 1 ,任务是在所有对(i,j)中找到最大LCM,以使i
例子:

方法:由于两个连续元素的LCM等于它们的倍数,因此很明显,最大LCM将为(N,N – 1)(N *(N – 1))
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the maximum LCM
// among all the pairs(i, j) of
// first n natural numbers
int maxLCM(int n)
{
    return (n * (n - 1));
}
 
// Driver code
int main()
{
    int n = 3;
 
    cout << maxLCM(n);
 
    return 0;
}


Java
// Java implementation of the approach
class GFG
{
     
// Function to return the maximum LCM
// among all the pairs(i, j) of
// first n natural numbers
static int maxLCM(int n)
{
    return (n * (n - 1));
}
 
// Driver code
public static void main(String[] args)
{
    int n = 3;
 
    System.out.println(maxLCM(n));
}
}
 
// This code is contributed by Code_Mech


Python3
# Python3 implementation of the approach
 
# Function to return the maximum LCM
# among all the pairs(i, j) of
# first n natural numbers
def maxLCM(n) :
 
    return (n * (n - 1));
 
# Driver code
if __name__ == "__main__" :
 
    n = 3;
 
    print(maxLCM(n));
 
# This code is contributed by AnkitRai01


C#
// C# implementation of the approach
using System;
     
class GFG
{
     
// Function to return the maximum LCM
// among all the pairs(i, j) of
// first n natural numbers
static int maxLCM(int n)
{
    return (n * (n - 1));
}
 
// Driver code
public static void Main(String[] args)
{
    int n = 3;
 
    Console.WriteLine(maxLCM(n));
}
}
 
// This code is contributed by Rajput-Ji


Javascript


输出:
6

时间复杂度: O(1)