Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Exploring Double Recursion

Revision en1, by Jabir_Nayan, 2025-08-20 11:35:23

Hello everyone,, While solving recently, I wanted to compute:gcd({lcm({ai,aj}) | i<j}) from the problem named Orac and LCM(link:https://codeforces.me/problemset/problem/1349/A).

Normally, We would just write two nested loops. But for fun and practice, I tried to implement it using double recursion – one recursion for the outer loop, and one recursion for the inner loop. This is of course not the most efficient solution for very large n (n<=100,000), but I found it to be a neat way of understanding how recursion can simulate loops,

If anyone has their own ideas, optimizations, or different recursive approaches, I would be very happy to learn from you. Please feel free to share your thoughts in the comments. Thanks in advance.

my submission:https://codeforces.me/contest/1349/submission/334634088

Tags recursion, gcd, lcm, nested recursion

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Jabir_Nayan 2025-08-20 11:35:23 845 Initial revision (published)