From 6c997d23ef2f14c05c14b62073e145d6547ffd61 Mon Sep 17 00:00:00 2001 From: chayan das Date: Fri, 18 Jul 2025 23:58:48 +0530 Subject: [PATCH] Create 18 July LCM Triplet --- 18 July LCM Triplet | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 18 July LCM Triplet diff --git a/18 July LCM Triplet b/18 July LCM Triplet new file mode 100644 index 0000000..48bc87e --- /dev/null +++ b/18 July LCM Triplet @@ -0,0 +1,71 @@ +class Solution { + + public: + + int gcd(int a, int b) + + { + + if (a == 0) + + return b; + + return gcd(b % a, a); + + } + + + + long long lcmTriplets(long long N) { + + long long y, x = N, f, s, c = 0; + + if(N == 2 || N == 1) + + return N; + + if(N&1) + + return (N)*(N-1)*(N-2); + + else { + + x -= 2; y=x; + + while(1 && c < 1) + + { + + if(gcd(x, N) == 1) { + + f = x*N*(N-1); + + ++c; + +}; + + --x; + + }c=0; N=N-1; --y; + + while(1 && c < 1 ) { + + if(gcd(y, N) == 1) { + + s = y*N*(N-1); + + ++c;} + + --y; + + } + + + + return max(f, s); + + } + + } + +};