QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: jiangly

Posted at: 2025-12-12 23:47:46

Last updated: 2025-12-12 23:47:51

Back to Problem

题解

把 $x$ 和 $2x+2$ 连一条边,则图是由一些链组成的,答案就是每条链长度除以 $2$ 上取整求和。

把 $n$ 加上 $2$,变成 $x$ 和 $2x$ 连边,最后只需答案减去 $1$(因为多了 $1$ 和 $2$)。

$x$ 和 $2x$ 连边时的答案就是 $n-\lfloor n/2\rfloor+\lfloor n/4\rfloor-\cdots$。这其实就是对每条链上进行容斥。

Comments

No comments yet.