Hi Everyone.

Now I'm wondering how to find the number of partition of an integer N(<=10^5).

Any advice?

The number of partition of 4 is 5.

4 = 4.

4 = 3 + 1.

4 = 2 + 2.

4 = 2 + 1 + 1.

4 = 1 + 1 + 1 + 1.

Thank You.

Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official.
×

# | User | Rating |
---|---|---|

1 | tourist | 3880 |

2 | jiangly | 3669 |

3 | ecnerwala | 3654 |

4 | Benq | 3627 |

5 | orzdevinwang | 3612 |

6 | Geothermal | 3569 |

6 | cnnfls_csy | 3569 |

8 | jqdai0815 | 3532 |

9 | Radewoosh | 3522 |

10 | gyh20 | 3447 |

# | User | Contrib. |
---|---|---|

1 | awoo | 161 |

2 | maomao90 | 160 |

3 | adamant | 156 |

4 | maroonrk | 153 |

5 | -is-this-fft- | 148 |

5 | SecondThread | 148 |

5 | atcoder_official | 148 |

8 | Petr | 147 |

9 | nor | 144 |

9 | TheScrasse | 144 |

Hi Everyone.

Now I'm wondering how to find the number of partition of an integer N(<=10^5).

Any advice?

The number of partition of 4 is 5.

4 = 4.

4 = 3 + 1.

4 = 2 + 2.

4 = 2 + 1 + 1.

4 = 1 + 1 + 1 + 1.

Thank You.

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/22/2024 19:56:13 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Auto comment: topic has been updated by YogayoG (previous revision, new revision, compare).I came up with following solution. It uses the fact that either minimal summand in the partition or ammount of summands is not too big. Let arrange the summands in the partition in the non decreasing order. Denote

f(i,j) — number of partitions of numberiif the minimal summand isj,g(i,j) — number of partitions of numberiif the amount of summands isj. Thenf(i,j) =f(i-j,j) +f(i,j+ 1) (we either put j as a new summand or increase the minimal summand),g(i,j) =g(i- 1,j- 1) +g(i-j,j) (we either put 1 as a new summand or we will have all the summands are greater than 1 then decrease all of them by 1 and return to the state when all the summands are greater or equal than 1). Letpbe such number that (p- 1) * (p- 1) ≤n,p*p>n. Lets=p- 1. We compute values ofg(i,j) for alli= 1...n,j= 1...s. Then lets calculate values off(i,p) for alli= 1...n. Iterate through the number of summand here and express it through the fungtiong: . Then we can calculate values off(i,j) for alli= 1...n,j= 1...s. Time and space complexity are . It seems pretty amazing to me that there is such a solution while before I encountered with such a problem and didn't know that it's possible to solve it with such complexity. Is it known that we can solve this problem with such complexity or better?You can also compute it using pentagonal numbers in . It's a bit easier to implemenent, but much less intuitive than your solution.

bciobanu I have read that before. And I can't understand why it works. Thanks for pointing me that it's easier to implement, I will trying to understand it.

Thank you ABalobanov for your solution. And seems your solution surely will pass the time limit.

On the OEIS page, the formula involving A001318 looks like it yields an solution

ifaddition and subtraction areO(1) (e.g., modulo an integer).Edit:this is essentially the same as bciobanu's comment above.