FLINT3.7.0-dev

n_is_perfect_power235, n_factor_power235

Synopsis#include <flint/ulong_extras.h>
int n_is_perfect_power235(ulong n)source
ulong n_factor_power235(ulong * exp, ulong n)source

n_is_perfect_power235 returns whether n is a square, cube or fifth power. n_factor_power235 returns the root r and sets *exp to k \in \{2, 3, 5\} if n = r^k, and otherwise returns 0.

Both functions first apply a sequence of modular tests, which rejects most inputs: each test looks up a 3-bit mask saying whether n can be a square, cube or fifth power modulo some small modulus, and the masks are combined with bitwise AND. For any bit that survives, the corresponding root is computed and checked exactly.

Cite this page

The FLINT team, “n_is_perfect_power235, n_factor_power235 (ulong_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/ulong_extras/n_is_perfect_power235.html (generated 2026-10-20).