Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions 18 July LCM Triplet
Original file line number Diff line number Diff line change
@@ -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);

}

}

};
Loading