Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

Filter by
Sorted by
Tagged with
26
votes
8answers
1k views

A083569: Smallest m not occurring earlier such that m+n is prime

Define a 1-indexed sequence as follows: A083569(1) = 1 A083569(n) where n is an integer ...
25
votes
6answers
1k views

Prime containment numbers (speed edition)

This is sequence A054261 The \$n\$th prime containment number is the lowest number which contains the first \$n\$ prime numbers as substrings. For example, the number \$235\$ is the lowest number ...
25
votes
16answers
1k views

Approximate Brun's Constant

Brun's constant is the value to which the sum of the reciprocals of twin prime pairs (1/p and 1/(p+2) where ...
25
votes
17answers
1k views

Counting +1 primes

Define that the natural number p is a +1 prime of the natural number n if p is a prime number and the standard binary representation (i.e., without leading zeroes) of p can be obtained by adding (i.e.,...
25
votes
6answers
2k views

Concatenating Primes

Challenge: You are given a string containing only digits. Your task is to output the minimum number of primes which must be concatenated to form the string. If this is impossible, output ...
24
votes
20answers
1k views

Sum pyramid of primes

Given a number N, the challenge is to get the sum of the pyramid of N primes. To clarify things, here is an example: Input: 4 We will list the first ...
24
votes
22answers
3k views

Bertrand's Primes

Bertrand's Postulate states that for every integer n ≥ 1 there is at least one prime p such that n < p ≤ 2n. In order to verify this theorem for n < 4000 ...
24
votes
20answers
2k views

Climb a step to a prime

The title of Numberphile's newest video, 13532385396179, is a fixed point of the following function f on the positive integers: Let n be a positive integer. Write the prime factorization in the ...
24
votes
22answers
6k views

Can even numbers become prime?

The Sequence Everyone knows the only even prime number is 2. Ho-hum. But, there are certain even numbers n where, when ...
24
votes
28answers
2k views

Magnanimous numbers

Given an positive integer as input determine if it is a magnanimous number. A magnanimous number is a number such that any insertion of a + sign between any two ...
24
votes
9answers
2k views

The Solitude of Prime Numbers

Recently I read the novel "The Solitude of Prime Numbers" where the main characters are somewhat compared to twin prime numbers ("always together, but never touching"). A twin prime is a prime ...
24
votes
2answers
901 views

Can a neural network recognize primes?

Background Recognizing primality seems like a poor fit for (artificial) neural networks. However, the universal approximation theorem states that neural networks can approximate any continuous ...
23
votes
25answers
3k views

The Möbius Function

The Möbius Function The Möbius function is an important number theoretic function. Your submission should accept a positive integer n and return the value of the ...
23
votes
20answers
2k views

Find the Maximal Prime Powers

A prime power is a positive integer n that can be written in the form n = pk where p is a prime and k is a positive integer. For example, some prime powers are ...
23
votes
26answers
2k views

Primes with prime bit-counts

Task Find all the non-negative integers up to and including a given non-zero positive integer n, that are prime and the count of 1's and ...
23
votes
19answers
4k views

Do I have a prime twin?

An Integer is prime if and only if it is positive and has exactly 2 distinct divisors: 1 and itself. A twin prime pair is made of two elements: p and ...
23
votes
11answers
1k views

Find the nth Fibohexaprime

The challenge this time is to find the nth Fibohexaprime. The definition of a Fibohexaprime is as following: We first observe a list with Fibonacci numbers: ...
23
votes
14answers
3k views

Reuse your code!

In this challenge we try to solve two important problems at once. They are: Given integers a and b, tell if ab-1 is a prime number. Given integers a and b, return nCr(a, b). Specifically, you must ...
23
votes
13answers
2k views

Prime Time Travel

Don't tell anyone, but I've nicked my uncle's time travel machine! My uncle is obsessed with prime numbers, though, and that shows in the machine — he has programmed it so that it can only go to dates ...
23
votes
1answer
338 views

It's factors all the way down!

This challenge is inspired by this fantastic animated diagram (thanks to flawr for posting it in chat). Given an input n, draw all of its prime factors as nested ...
22
votes
26answers
9k views

List Prime Numbers [duplicate]

Introduction Prime numbers are simple, right? Well, now you get your chance to find out! Challenge You must write a program or function that takes an input n and ...
22
votes
20answers
2k views

Is it a super-prime?

Background A super-prime is a prime number whose index in the list of all primes is also prime. The sequence looks like this: 3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, ... This ...
22
votes
23answers
3k views

Find the prime factors

In this task, you have to write a program, that computes the prime factors of a number. The input is a natural number 1 < n < 2^32. The output is a list of the prime factors of the number in the ...
22
votes
14answers
2k views

Prime Wednesdays

Prime Wednesdays Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime ...
22
votes
28answers
2k views

Largest Prime Exponents

Given an integer n >= 2, output the largest exponent in its prime factorization. This is OEIS sequence A051903. Example Let ...
22
votes
19answers
2k views

Is this a consecutive-prime/constant-exponent number?

A while ago, I had a look at the prime factorization of 27000: 27000 = 23 × 33 × 53 There are two special things about that: consecutive-prime: The primes are consecutive: 2 is the ...
22
votes
16answers
2k views

Sort a number's divisors by prime factorization

Given an input of an integer ≥ 2, output a list of its divisors sorted by the exponents in their prime factorizations, in ascending order, ordering first by the largest prime, then by the second ...
22
votes
6answers
2k views

Triangular Ulam spiral

We've had a couple of challenges about the Ulam spiral. But that's not enough. In this challenge we will plot a triangular Ulam spiral (as opposed to the usual, square Ulam spiral). Here's a sketch ...
22
votes
5answers
893 views

Fastest Home Prime Generator

What is a home prime? For an example, take HP(4). First, find the prime factors. The prime factors of 4 (in numerical order from least to greatest, always) are 2, 2. Take those factors as a literal ...
22
votes
3answers
2k views

Factoring a 64-bit integer

Write a GOLF assembly program that reads an integer from stdin (followed by a trailing newline), and outputs its prime factors seperated by newlines, followed by a trailing newline on stdout. The ...
21
votes
32answers
1k views

A prime test that's LITERALLY prime

Write a program that will test the primality of a specified number, and give the output as a Boolean value (True is prime). Your prime test can (but doesn't have to) be valid for the number 1. Here'...
21
votes
13answers
1k views

Combinatorial products of unique primes

Statement of problem Given a set of unique, consecutive primes (not necessarily including 2), generate the products of all combinations of first powers of these primes — e.g., no repeats — and also 1....
21
votes
22answers
2k views

Get thee behind me Satan-Prime!

Satan-Primes who are they? they are Primes containing 666 these are Satan-Primes:...
21
votes
14answers
2k views

Prime containment numbers (golf edition)

This is sequence A054261. The \$n\$th prime containment number is the lowest number which contains the first \$n\$ prime numbers as substrings. For example, the number \$235\$ is the lowest number ...
21
votes
10answers
1k views

Prime factors buddies

Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of ...
21
votes
6answers
3k views

Find the largest fragile prime

Consider the function Remove(n, startIndex, count) that removes count digits from the number ...
21
votes
9answers
3k views

Finding prime numbers without using “prime characters”

Your task, if you choose to accept it, is to write a program/function that accepts an integer N as input. The program/function should output/return a list of the first N prime numbers. But here's the ...
21
votes
5answers
768 views

Is my number Unique

In this challenge we learned a way to encode every positive integer using factor trees. Here is how it works: The empty string has value of 1. (S) where ...
21
votes
10answers
1k views

Finding Lonely Primes

Lonely primes (as I call them) are primes, where given a number grid with width w ≥ 3, are primes which do not have any other primes adjacent to them orthogonally ...
20
votes
16answers
3k views

​Cuban​ ​Primes

Given a natural number \$n\$, return the \$n\$-th cuban prime. Cuban Primes A cuban prime is a prime number of the form $$p = \frac{x^3-y^3}{x-y}$$ where \$y>0\$ and \$x = 1+y\$ or \$x = 2+y\$ ...
20
votes
16answers
2k views

Factor-poor numbers

If a positive integer \$N > 2\$ has (strictly) less prime factors (without counting multiplicities) than its successor and its predecessor, we will call it a factor-poor number. In other words, \$...
20
votes
9answers
972 views

Novel Prime Factors of Repunits

The Background Folks were talking prime factorization in chat and we found ourselves talking about repunits. Repunits are a subset of the numbers known as repdigits, which are numbers consisting of ...
20
votes
11answers
1k views

Find the Emirps!

An emirp is a non-palindromic prime which, when reversed, is also prime. The list of base 10 emirps can be found on OEIS. The first six are: ...
20
votes
2answers
927 views

Prime polynomials

Given a polynomial, determine whether it's prime. A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the ...
19
votes
29answers
2k views

Cops and Robbers: Redacted Primality (Cops' Thread)

This challenge was originally sandboxed by Magic Octopus Urn; I adopted and posted it with his permission. This is the cops' thread. The robbers' thread is here. The challenge Step One: Write a ...
19
votes
28answers
3k views

Calculate prime gaps

Finding primes is a programming rite of passage and very frequently a first serious program someone crates (usually with trial division). But primes alone are already worn out. A next far more ...
19
votes
19answers
1k views

Some Prime Peerage

(Randomly inspired by https://mathoverflow.net/q/339890) (Related: 1, 2) Given an input list of distinct prime numbers (e.g., [2, 5, 7]), and a integer ...
19
votes
12answers
3k views

Sum of smallest prime factors

SF(n) is a function which computes the smallest prime factor for a given number n. We'll call T(N) the sum of every SF(n) with 2 <= n <= N. T(1) = 0 (the sum is over 0 summands) T(2) = 2 (2 ...
19
votes
5answers
2k views

Find largest prime which is still a prime after digit deletion

Over at https://math.stackexchange.com/questions/33094/deleting-any-digit-yields-a-prime-is-there-a-name-for-this the following question is asked. How many primes are there that remain prime after you ...
19
votes
4answers
714 views

Fermat's factorization helper

We'd like to factorize a semiprime \$N\$. The goal of this challenge is to find two small integers \$u\$ and \$v\$ such that \$uvN\$ can be trivially factorized with Fermat's method, thus allowing to ...