Editorial | "LightOJ 1289" LCM from 1 to n
Editorial for LightOJ 1289, computing lcm(1,2,...,n) in O(n) with a linear sieve plus a recurrence relation.
Machine-translated from the Chinese original.
Problem
Find , multiple test cases.
Editorial
MicroMaker, resident OI legend, reckoned it had something to do with Euler’s totient function, but I stared at it for a while and came up with nothing. So brute force it is.
First, use a linear sieve to sieve out all primes in . Then consider the following property:
If , where is a prime, then ; otherwise, .
Since the time limit for this problem is seconds, once we have the recurrence we can push a hundred million through in .
