CF - Orac & LCM

Author: Benjamin Qi

Table of Contents

Solution
Edit on Github

Official Editorial

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;
3
4using ll = long long;
5
6ll a,b;
7// a stores minimum exponents
8// b stores second minimum exponents
9int 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!

Give Us Feedback on CF - Orac & LCM!