In this particular case the set AiA_i - previously mentioned in the tutorial section - denotes how many qudruples {V1,V2,V3,V4}\{ V_1, V_2, V_3, V_4\} there are such that iVj,i[1,4]i \mid V_j, \forall i \in [1,4] . The global answer is i=1 maxval Ai\bigg| \bigcup_{i=1}^{\text{ maxval }} A_i \bigg|.

C++

#include <iostream>
#include <vector>
using namespace std;
void precompute(vector<int> &mobius, vector<int> &comb) {
mobius[1] = -1;
for (int i = 1; i < (int)mobius.size(); i++) {
if (mobius[i]) {
mobius[i] = -mobius[i];

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!