Tutorial uses mobius function to solve this problem. How can we solve this using DP, as I have seen many people use it in their solutions.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3857 |
| 2 | jiangly | 3810 |
| 3 | maroonrk | 3534 |
| 4 | tourist | 3528 |
| 5 | Kevin114514 | 3510 |
| 6 | turmax | 3411 |
| 7 | Um_nik | 3387 |
| 8 | Radewoosh | 3367 |
| 9 | heuristica | 3322 |
| 10 | strapple | 3317 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | maspy | 150 |
| 3 | Um_nik | 145 |
| 4 | Errichto | 139 |
| 5 | adamant | 136 |
| 6 | maroonrk | 134 |
| 7 | DNR | 133 |
| 7 | nik_exists | 133 |
| 9 | AmShZ | 130 |
| 10 | Dominater069 | 129 |
Tutorial uses mobius function to solve this problem. How can we solve this using DP, as I have seen many people use it in their solutions.
| Name |
|---|



Let $$$dp[i]$$$ be the number of ways with $$$\gcd = i$$$.
If you calculate it in descending order of $$$i$$$, $$$dp[i] =$$$ (number of ways with values multiples of $$$i$$$) — $$$\sum_{k=2}^{\lfloor m/i \rfloor} dp[ik]$$$.
You can check out similar techniques in this blog.
Got this bit, thanks! I was looking at your solution 125973986 Just wanted to know if you're storing in kn[i][j] : number of ways after i terms and upto jth multiple of g, or something else?
The former.