All Euler problems
Project Euler

Cyclogenic Polynomials

A monic polynomial p(x) is n -cyclogenic if p(x)q(x) = x^n - 1 for some monic q(x) in Z[x], with n minimal. P_n(x) = sum of all n -cyclogenic polynomials. Q_N(x) = sum_(n=1)^N P_n(x). Given Q_10(2)...

Source sync Apr 19, 2026
Problem #0797
Level Level 34
Solved By 235
Languages C++, Python
Answer 47722272
Length 238 words
algebranumber_theorybrute_force

Problem Statement

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

A monic polynomial is a single-variable polynomial in which the coefficient of highest degree is equal to $1$.

Define $\mathcal{F}$ to be the set of all monic polynomials with integer coefficients (including the constant polynomial $p(x)=1$). A polynomial $p(x)\in\mathcal{F}$ is cyclogenic if there exists $q(x)\in\mathcal{F}$ and a positive integer $n$ such that $p(x)q(x)=x^n-1$. If $n$ is the smallest such positive integer then $p(x)$ is -cyclogenic.

Define $P_n(x)$ to be the sum of all $n$-cyclogenic polynomials. For example, there exist ten 6-cyclogenic polynomials (which divide $x^6-1$ and no smaller $x^k-1$): \begin{align*} &x^6-1&&x^4+x^3-x-1&&x^3+2x^2+2x+1&&x^2-x+1\\ &x^5+x^4+x^3+x^2+x+1&&x^4-x^3+x-1&&x^3-2x^2+2x-1\\ &x^5-x^4+x^3-x^2+x-1&&x^4+x^2+1&&x^3+1 \end{align*} giving $$P_6(x)=x^6+2x^5+3x^4+5x^3+2x^2+5x$$ <p>Also define</p> $$Q_N(x)=\sum_{n=1}^N P_n(x)$$ It's given that $Q_{10}(x)=x^{10}+3x^9+3x^8+7x^7+8x^6+14x^5+11x^4+18x^3+12x^2+23x$ and $Q_{10}(2) = 5598$.

Find $Q_{10^7}(2)$. Give your answer modulo $1\,000\,000\,007$.

Problem 797: Cyclogenic Polynomials

Mathematical Analysis

An nn-cyclogenic polynomial divides xn1x^n - 1 in Z[x]\mathbb{Z}[x] and does not divide xm1x^m - 1 for any m<nm < n. The divisors of xn1x^n - 1 are products of cyclotomic polynomials Φd(x)\Phi_d(x) for dnd | n.

A monic divisor of xn1x^n-1 is a product dSΦd(x)\prod_{d \in S} \Phi_d(x) for some subset S{d:dn}S \subseteq \{d : d|n\}. It is nn-cyclogenic if nn is the minimal such value, meaning SS contains at least one dd for which nn is the smallest multiple.

Equivalently, the polynomial is nn-cyclogenic iff lcm(S)=n\text{lcm}(S) = n, where SS is the set of cyclotomic indices used.

Pn(x)P_n(x) is the sum over all subsets S{d:dn}S \subseteq \{d : d|n\} with lcm(S)=n\text{lcm}(S) = n of dSΦd(x)\prod_{d \in S} \Phi_d(x).

By Mobius inversion on the lcm condition, Pn(2)P_n(2) can be computed from the product structure of cyclotomic values Φd(2)\Phi_d(2).

Concrete Examples and Verification

See problem statement for verification data.

Derivation and Algorithm

The algorithm follows from the mathematical analysis above, implemented with appropriate data structures for the problem’s scale.

Proof of Correctness

Correctness follows from the mathematical derivation and verification against provided test cases.

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

Must handle the given input size. See analysis for specific bounds.

Answer

47722272\boxed{47722272}

Code

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

C++ project_euler/problem_797/solution.cpp
#include <bits/stdc++.h>
using namespace std;
/*
 * Problem 797: Cyclogenic Polynomials
 * A monic polynomial $p(x)$ is $n$-cyclogenic if $p(x)q(x) = x^n - 1$ for some monic $q(x) \in \mathbb{Z}[x]$, with $n$ mi
 */
int main() {
    printf("Problem 797: Cyclogenic Polynomials\n");
    // See solution.md for algorithm details
    return 0;
}