CF - Orac & LCM
Author: Benjamin Qi
Solution
For each prime, the second-to-lowest exponent of the prime that occurs in any of the numbers in the input is the exponent of this prime that will appear in the final answer.
Here's a short solution that accomplishes this without explicitly computing any prime factorizations!
1#include <bits/stdc++.h>2using namespace std;34using ll = long long;56ll a,b;7// a stores minimum exponents8// b stores second minimum exponents9int n;10
If it's hard to understand what exactly this code is doing at first glance, a good first step is to simulating the code in the case where each is a power of the same prime (say, ). If the algorithm works for this case, then it will also work in the general case since the contributions of different primes are computed independently and multiplied together.
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!