
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find three integers less than or equal to N such that their LCM is maximum in C++
In this tutorial, we will be discussing a program to find three integers less than or equal to N such that their LCM is maximum.
For this we will be provided with an integer value. Our task is to find other three integers smaller than the given value such that their LCM is maximum.
Example
#include <bits/stdc++.h> using namespace std; //finding three integers less than given value //having maximum LCM void findMaximumLCM(int n) { if (n % 2 != 0) { cout << n << " " << (n - 1) << " " << (n - 2); } else if (__gcd(n, (n - 3)) == 1) { cout << n << " " << (n - 1) << " " << (n - 3); } else { cout << (n - 1) << " " << (n - 2) << " " << (n - 3); } } int main() { int number = 34; findMaximumLCM(number); return 0; }
Output
34 33 31
- Related Articles
- Find three integers less than or equal to N such that their LCM is maximum - C++
- Find maximum number of elements such that their absolute difference is less than or equal to 1 in C++
- Find unique pairs such that each element is less than or equal to N in C++
- C++ program to find unique pairs such that each element is less than or equal to N
- Find maximum product of digits among numbers less than or equal to N in C++
- Find all factorial numbers less than or equal to n in C++
- Find maximum sum array of length less than or equal to m in C++
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k in C++
- Find Multiples of 2 or 3 or 5 less than or equal to N in C++
- Print all prime numbers less than or equal to N in C++
- Maximum sum of distinct numbers such that LCM of these numbers is N in C++
- Maximum sum subarray having sum less than or equal to given sums in C++
- Print all Semi-Prime Numbers less than or equal to N in C++
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Program to Find Out Integers Less than n Containing Multiple Similar Digits in C++

Advertisements