Given an **integer N**, the task is to print any pair of integers that have the sum of GCD and LCM equal to N.

**Examples:**

Input:N = 14

Output:1, 13

Explanation:

For the given pair we have GCD(1, 13) = 1 and LCM (1, 13) = 13. Sum of GCD and LCM = 1 + 13 = 14.

Input:2

Output:1 1

Explanation:

For the given pair we have GCD(1, 1) = 1 and LCM (1, 1) = 1. Sum of GCD and LCM = 1 + 1 = 2.

**Approach:**

To solve the problem mentioned above let us consider the pair to be (1, n-1). **GCD of (1, n-1) = 1 and LCM of (1, n-1) = n – 1**. So the sum of GCD and LCM = 1 + (n – 1) = n. Hence the pair (1, n – 1) will be the pair which has the sum of GCD and LCM equal to N.

Below is the implementation of the above approach:

## C++

`// C++ implementation to Print any pair of integers ` `// whose summation of GCD and LCM is equal to integer N ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to print the required pair ` `void` `printPair(` `int` `n) ` `{ ` ` ` `// print the pair ` ` ` `cout << 1 << ` `" "` `<< n - 1; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 14; ` ` ` ` ` `printPair(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to print any pair of integers ` `// whose summation of GCD and LCM is equal to integer N ` `class` `GFG{ ` ` ` `// Function to print the required pair ` `static` `void` `printPair(` `int` `n) ` `{ ` ` ` `// Print the pair ` ` ` `System.out.print(` `1` `+ ` `" "` `+ (n - ` `1` `)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `14` `; ` ` ` `printPair(n); ` `} ` `} ` ` ` `// This code is contributed by gauravrajput1 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation to print any ` `# pair of integers whose summation of ` `# GCD and LCM is equal to integer N ` ` ` `# Function to print the required pair ` `def` `printPair(n): ` ` ` ` ` `# Print the pair ` ` ` `print` `(` `"1"` `, end ` `=` `" "` `) ` ` ` `print` `(n ` `-` `1` `) ` ` ` `# Driver code ` `n ` `=` `14` `printPair(n) ` ` ` `# This code is contributed by PratikBasu ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to print any pair ` `// of integers whose summation of ` `// GCD and LCM is equal to integer N ` `using` `System; ` ` ` `public` `class` `GFG{ ` ` ` `// Function to print the required pair ` `static` `void` `printPair(` `int` `n) ` `{ ` ` ` ` ` `// Print the pair ` ` ` `Console.Write(1 + ` `" "` `+ (n - 1)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n = 14; ` ` ` `printPair(n); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

**Output:**

1 13

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Sum of LCM(1, n), LCM(2, n), LCM(3, n), ... , LCM(n, n)
- Find any pair with given GCD and LCM
- Pair of integers having least GCD among all given pairs having GCD exceeding K
- Maximum possible GCD for a pair of integers with sum N
- Generate a pair of integers from a range [L, R] whose LCM also lies within the range
- Find pair with maximum GCD for integers in range 2 to N
- Maximum possible GCD for a pair of integers with product N
- Count of all possible pairs having sum of LCM and GCD equal to N
- Check if any permutation of N equals any power of K
- Check if there is any pair in a given range with GCD is divisible by k
- Series with largest GCD and sum equals to n
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- GCD, LCM and Distributive Property
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Levelwise Alternating GCD and LCM of nodes in Segment Tree
- Minimum LCM and GCD possible among all possible sub-arrays
- Recursive program to print formula for GCD of n integers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Finding LCM of more than two (or array) numbers without using GCD

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.