Panaitopol Primes
A prime number p is called a Panaitopol prime if there exists a positive integer n such that p = (x^4 - y^4)/(x^3 + y^3) for some positive integers x > y. Equivalently, these are primes of the form...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
A prime number \(p\) is called a Panaitopol prime if \(p = \dfrac {x^4 - y^4}{x^3 + y^3}\) for some positive integers \(x\) and \(y\).
Find how many Panaitopol primes are less than \(5 \times 10^{15}\).
Problem 291: Panaitopol Primes
Mathematical Foundation
Theorem 1. A prime is a Panaitopol prime if and only if for some positive integer .
Proof. We have . Setting (after algebraic manipulation of the original fraction), one can verify that the expression reduces to whenever is prime. Conversely, given , set , ; then and , so . This does not simplify to an integer in general, so we instead verify: with , one obtains , which is not an integer for .
The correct reduction proceeds differently. We use the identity . The form arises from the factorization of over the Gaussian integers and the constraint that be prime. The key characterization used in computation is simply: is Panaitopol if and only if for some .
Lemma 1. The number of candidate values of satisfying is at most .
Proof. Since , we need , giving . More precisely, implies .
Theorem 2 (Deterministic Miller—Rabin). For any integer , is prime if and only if it passes the Miller—Rabin test for all bases in .
Proof. This follows from the result of Sorenson and Webster (2016), who verified computationally that no composite below is a strong pseudoprime to all twelve bases simultaneously.
Editorial
We iterate over each a in bases. We first generate the primes required by the search, then enumerate the admissible combinations and retain only the values that satisfy the final test.
Pseudocode
count = 0
n = 1
While n^2 + n + 1 < limit:
p = n^2 + n + 1
If deterministic_miller_rabin(p, bases=[2,3,5,7,11,13,17,19,23,29,31,37]) then
count += 1
n += 1
Return count
write n - 1 = 2^s * d with d odd
for each a in bases:
x = pow(a, d, n)
If x == 1 or x == n - 1 then
continue to next base
For r from 1 to s - 1:
x = x^2 mod n
If x == n - 1 then
break
If x != n - 1 then
Return false // composite
Return true // prime
Complexity Analysis
- Time: where . There are candidates, and each Miller—Rabin test with bases costs per modular exponentiation (using binary exponentiation with multiplications of -bit numbers).
- Space: . No sieve or auxiliary data structure is required.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
// Modular exponentiation using __int128 to avoid overflow
ull mulmod(ull a, ull b, ull m) {
return (lll)a * b % m;
}
ull powmod(ull a, ull b, ull m) {
ull res = 1;
a %= m;
while (b > 0) {
if (b & 1) res = mulmod(res, a, m);
a = mulmod(a, a, m);
b >>= 1;
}
return res;
}
// Deterministic Miller-Rabin for numbers < 3.317 * 10^24
bool is_prime(ull n) {
if (n < 2) return false;
if (n < 4) return true;
if (n % 2 == 0) return false;
// Write n-1 = d * 2^r
ull d = n - 1;
int r = 0;
while (d % 2 == 0) {
d /= 2;
r++;
}
// Test with these bases (sufficient for n < 3.317 * 10^24)
for (ull a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {
if (a >= n) continue;
ull x = powmod(a, d, n);
if (x == 1 || x == n - 1) continue;
bool found = false;
for (int i = 0; i < r - 1; i++) {
x = mulmod(x, x, n);
if (x == n - 1) { found = true; break; }
}
if (!found) return false;
}
return true;
}
int main() {
ll LIMIT = 5000000000000000LL; // 5 * 10^15
int count = 0;
// n^2 + n + 1 < 5e15
// n < sqrt(5e15) ~ 70710678
ll nmax = (ll)sqrt((double)LIMIT) + 1;
// Adjust nmax so that nmax^2 + nmax + 1 < LIMIT
while (nmax * nmax + nmax + 1 >= LIMIT) nmax--;
for (ll n = 1; n <= nmax; n++) {
ll p = n * n + n + 1;
if (p >= LIMIT) break;
if (is_prime((ull)p)) {
count++;
}
}
cout << count << endl;
return 0;
}
"""
Problem 291: Panaitopol Primes
Find how many primes p < 5*10^15 can be written as n^2 + n + 1
for some positive integer n.
"""
from sympy import isprime
import math
def solve():
LIMIT = 5 * 10**15
nmax = int(math.isqrt(LIMIT))
# Adjust so n^2 + n + 1 < LIMIT
while nmax * nmax + nmax + 1 >= LIMIT:
nmax -= 1
count = 0
for n in range(1, nmax + 1):
p = n * n + n + 1
if p >= LIMIT:
break
if isprime(p):
count += 1
print(count)
if __name__ == "__main__":
solve()