DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Pillow CPU

Back to problem

Editorial

Let f(n)f(n)f(n) be the expected remaining time when the current value is nnn. We have f(1)=0f(1)=0f(1)=0.

For n>1n>1n>1, the value decreases only when the chosen integer is a divisor of nnn. If τ(n)\tau(n)τ(n) is the number of positive divisors of nnn, then there are τ(n)−1\tau(n)-1τ(n)−1 valid choices among 2,3,⋯ ,n2,3,\cdots,n2,3,⋯,n.

Writing the expectation after one choice gives

f(n)=1+n−τ(n)n−1f(n)+1n−1∑x∣nx≥2f(n/x).\begin{aligned} f(n) &=1+\frac{n-\tau(n)}{n-1}f(n) +\frac{1}{n-1}\sum_{\substack{x\mid n\\x\ge 2}} f(n/x). \end{aligned}f(n)​

As xxx ranges over the divisors of nnn that are at least 222, n/xn/xn/x ranges over every proper divisor of nnn exactly once. Rearranging yields

f(n)=n−1+∑d∣nd<nf(d)τ(n)−1.f(n)=\frac{n-1+\displaystyle\sum_{\substack{d\mid n\\d<n}}f(d)}{\tau(n)-1}.f(n)=τ(n)−1n

Only values f(d)f(d)f(d) with d<nd<nd<n appear on the right-hand side, so we may compute the values in increasing order of nnn.

Let MMM be the maximum input value over all test cases. We can preprocess all answers in O(Mlog⁡M)O(M\log M)O(MlogM). Store in SnS_nSn​ the sum of f(d)f(d) over proper divisors of , and in the number of proper divisors. Immediately after computing , add and to the corresponding arrays for every multiple . The total number of such updates is

∑n=1M⌊Mn⌋=O(Mlog⁡M).\sum_{n=1}^{M}\left\lfloor\frac{M}{n}\right\rfloor=O(M\log M).n=1∑M​⌊nM​

For each test case, print the precomputed value f(N)f(N)f(N) rounded to two digits after the decimal point.

Solution written by GPT5.6

=1+n−1n−τ(n)​f(n)+n−11​x∣nx≥2​∑​f(n/x).
​
−
1
+
d∣nd<n​∑​
f
(
d
)
​
.
f(d)
ddd
nnn
CnC_nCn​
f(n)f(n)f(n)
f(n)f(n)f(n)
111
2n,3n,⋯2n,3n,\cdots2n,3n,⋯
⌋
=
O(MlogM).