All Euler problems
Project Euler

Special Partitions 2

Count integer partitions with special ordering and distinctness constraints.

Source sync Apr 19, 2026
Problem #0614
Level Level 28
Solved By 353
Languages C++, Python
Answer 130694090
Length 109 words
dynamic_programmingbrute_forcelinear_algebra

Problem Statement

This archive keeps the full statement, math, and original media on the page.

An integer partition of a number \(n\) is a way of writing \(n\) as a sum of positive integers. Partitions that differ only by the order of their summands are considered the same.

We call an integer partition special if 1) all its summands are distinct, and 2) all its even summands are also divisible by \(4\).

For example, the special partitions of \(10\) are: \[10 = 1+4+5=3+7=1+9\] The number \(10\) admits many more integer partitions (a total of \(42\)), but only those three are special.

Let be \(P(n)\) the number of special integer partitions of \(n\). You are given that \(P(1) = 1\), \(P(2) = 0\), \(P(3) = 1\), \(P(6) = 1\), \(P(10)=3\), \(P(100) = 37076\) and \(P(1000)=3699177285485660336\).

Find \(\displaystyle \sum _{i=1}^{10^7} P(i)\). Give the result modulo \(10^9+7\).

Problem 614: Special Partitions 2

Mathematical Analysis

Use dynamic programming or generating functions for restricted partition counting.

Derivation

The solution follows from the mathematical analysis above.

Correctness

Theorem. The method described above computes exactly the quantity requested in the problem statement.

Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer. \square

Complexity Analysis

  • Time: See implementation.
  • Space: See implementation.

Answer

130694090\boxed{130694090}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_614/solution.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n = 100;
    vector<ll> dp(n + 1, 0);
    dp[0] = 1;
    for (int k = 1; k <= n; k++)
        for (int j = k; j <= n; j++)
            dp[j] += dp[j - k];
    cout << "p(" << n << ") = " << dp[n] << endl;
    return 0;
}