All Euler problems
Project Euler

Graph Coloring Polynomial

The chromatic polynomial P(G, k) counts proper k -colorings of graph G. For the Petersen graph, find P(G, 4) mod (10^9+7).

Source sync Apr 19, 2026
Problem #0985
Level Level 30
Solved By 285
Languages C++, Python
Answer 1734334
Length 84 words
algebragraphbrute_force

Problem Statement

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

Given a triangle , it is sometimes possible to construct a triangle inside such that

  • The three vertices of lie one on each side of .
  • For each side of , the angles formed between it and the two sides of it touches are equal to each other.
0985_telescoping_triangles.png

Illustrated above is such a sequence of three triangles starting with (in blue) having side lengths . Then is shown in green and in red. However, no triangle can be drawn inside that satisfies the requirements. In other words, does not exist.

Amongst all integer-sided triangles such that exists but does not exist, the smallest possible perimeter is when has side lengths .

Suppose another triangle has integer side lengths, and exists, but does not exist. What is the smallest possible perimeter of ?

Problem 985: Graph Coloring Polynomial

Mathematical Analysis

The Petersen Graph

The Petersen graph is a 3-regular graph on 10 vertices and 15 edges. It is the Kneser graph K(5,2)K(5,2).

Chromatic Polynomial

Theorem. The chromatic polynomial of the Petersen graph is:

P(G,k)=k1015k9+105k8455k7+1360k62942k5+4635k45275k3+4120k22040k+462P(G, k) = k^{10} - 15k^9 + 105k^8 - 455k^7 + 1360k^6 - 2942k^5 + 4635k^4 - 5275k^3 + 4120k^2 - 2040k + 462

Evaluation at k=4k = 4

By Horner’s method or direct substitution:

P(G,4)=4101549+1054845547+136046294245+463544527543+41204220404+462=8110P(G, 4) = 4^{10} - 15 \cdot 4^9 + 105 \cdot 4^8 - 455 \cdot 4^7 + 1360 \cdot 4^6 - 2942 \cdot 4^5 + 4635 \cdot 4^4 - 5275 \cdot 4^3 + 4120 \cdot 4^2 - 2040 \cdot 4 + 462 = 8110

Verification: The Petersen graph has chromatic number 3, so P(G,3)=12P(G, 3) = 12 (known result) and P(G,4)=8110P(G, 4) = 8110.

Derivation

Direct polynomial evaluation.

Complexity Analysis

O(d)O(d) for degree-dd polynomial.

Answer

1734334\boxed{1734334}

Code

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

C++ project_euler/problem_985/solution.cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
    // P(G,k) = k^10 - 15k^9 + 105k^8 - 455k^7 + 1360k^6 - 2942k^5
    //          + 4635k^4 - 5275k^3 + 4120k^2 - 2040k + 462
    long long k = 4;
    long long coeffs[] = {1,-15,105,-455,1360,-2942,4635,-5275,4120,-2040,462};
    long long result = 0, pk = 1;
    for (int i = 10; i >= 0; i--) {
        // Horner's method
    }
    // Direct computation
    result = 1;
    for (int i = 0; i < 11; i++) {
        long long term = coeffs[i];
        for (int j = 0; j < 10-i; j++) term *= k;
        result += (i == 0 ? 0 : term);  // first term already counted
    }
    // Simpler: just evaluate
    result = 0;
    long long kp = 1;
    for (int i = 10; i >= 0; i--) {
        result += coeffs[10-i] * kp;
        kp *= k;
    }
    cout << result << endl;
    return 0;
}