Official

B - Triple Pair Editorial by evima


We have two solutions, so we will explain both.

1: An \(\mathrm{O}(\sqrt N)\) solution obtained by considering the maximum of \(x,y,z\) (this page)

2: An \(\mathrm{O}(\sqrt N)\) solution obtained by considering the median of \(x,y,z\) (https://atcoder.jp/contests/arc160/editorial/6382)


From here, let’s define \(M = \lfloor \sqrt N \rfloor\).

When \(\max(x,y,z) \le M\)

The condition is always satisfied. The number of such \((x,y,z)\) is \(M^3\).

When \(\max(x,y,z) > M\)

From \((M+1)^2 > N\), note that only one variable takes the maximum value. Let’s set \(x > y,z\). When \(x\) is fixed, the condition is equivalent to \(y,z \le \left\lfloor\frac{N}{x} \right\rfloor\).

Considering that there are three choices for which of \(x, y, z\) takes the maximum value, the number of \((x,y,z)\) that satisfy the condition is \(3 \times \sum_{i=M+1}^{N} \left\lfloor\frac{N}{i}\right\rfloor ^2\). Since there are only \(\mathrm{O}(\sqrt N)\) different values of \(\frac{N}{i}\), this number can be calculated in \(\mathrm{O}(\sqrt N)\).

Therefore, one can solve this problem in \(\mathrm{O}(\sqrt N)\) for each case. This is sufficiently fast.

posted:
last update: