# Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

307 questions
Filter by
Sorted by
Tagged with
3k views

### Is the word coprime?

Given a word, treat every letter as it's number in English alphabet (so a becomes 1, b becomes 2, ...
2k views

### Prime numbers in large number

Given a large number (in base 10), such as 1234567891011121314151617, find prime "subnumbers" in it. A prime "subnumber" is a consecutive sequence of digits (taken from the input), which represents a ...
2k views

### The number of ways a number is a sum of consecutive primes

Given an integer greater than 1, output the number of ways it can be expressed as the sum of one or more consecutive primes. Order of summands doesn't matter. A sum can consist of a single number (...
717 views

### Compute the minimum $a(n)>a(n-1)$ such that $a(1)+a(2)+\dots+a(n)$ is prime (OEIS A051935)

Background Consider the following sequence (A051935 in OEIS): Start with the term $2$. Find the lowest integer $n$ greater than $2$ such that $2+n$ is prime. Find the lowest integer $n'$ ...
442 views

### Goldbach's Comet

Back to back challenges I guess. Hopefully this one is more clear than the last. Background I was playing around with Goldbach's conjecture, and decided to plot evens (on the x-axis) vs the number ...
141 views

### number decomposition [duplicate]

It's been a while since I posted here, so here we go another day another challenge. Challenge : Given a number(n) split it into it's prime factors. Input : A ...
5k views

### Primality testing formula

Your goal is to determine whether a given number n is prime in the fewest bytes. But, your code must be a single Python 2 expression on numbers consisting of only ...
6k views

### Calculate the sum of the first n prime numbers

I'm surprised that this challenge isn't already here, as it's so obvious. (Or I'm surprised I couldn't find it and anybody will mark it as a duplicate.) Task Given a non-negative integer $n$, ...
2k views

### Recover the power from the prime power

It seems that many people would like to have this, so it's now a sequel to this challenge! Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n ...
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 ...
2k views

### Recover the prime from the prime power

Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n is a natural number. Task: Given a prime power pn > 1, return the prime p. Testcases: <...
425 views

### It's getting harder and harder to be composite these days

Given a non-empty list L of integers greater than 1, we define d(L) as the smallest positive integer such that n + d(L) is composite for each n in L. We define the sequence an as: a0 = 2 ai+1 is the ...
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 1st prime, 3 is ...
2k views

### Prime or highest factor

Challenge: Given an array of non-negative whole numbers numbers in the range of 0 to Infinity, Check whether all of them are primes or not. (You can take input as ...
1k views

### Am I a Pillai prime?

A Pillai prime is a prime number $p$ for which there exists some positive $m$ such that $(m! + 1) \equiv 0 \:(\text{mod } p)$ and $p \not\equiv 1\:(\text{mod }m)$. In other words, an ...
2k views

### Prime Factor Encoding

How the encoding works Given a list of bits: Hold a prime (starting with 2) Have a list For each bit in the input If it's the same as the previous bit, add the ...
2k views

### 1, 2, 3, 14... or is it 15?

A well known song by the Irish rock band U2 starts with the singer Bono saying "1, 2, 3, 14" in Spanish ("uno, dos, tres, catorce"). There are various theories as to the significance of those numbers....
1k views

### Some Lonely Primes

I know, I know, yet another primes challenge... Related A lonely (or isolated) prime is a prime number p such that p-2, ...
143 views

### Find prime factors of sum of non-composite Fibonacci numbers up to n

The Challenge Given a number, find the sum of the non-composite numbers in the Fibonacci sequence up to that number, and find the prime factors of the sum. For example, if you were given 8, the non-...
207 views

tl;dr: Output the values where the reduced prime factorization leader changes. Every positive integer has a unique prime factorization. Let's call the reduced prime factorization just the list of ...
780 views

### Formerly Composite Numbers

Sequence Definition Construct a sequence of positive integers a(n) as follows: a(0) = 4 Each term ...
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 ...
788 views

### Cops and Robbers: Redacted Primality (Robbers' Thread)

This is the robbers' thread. The cops' thread is here. Your challenge is to take an uncracked submission from the cops' thread and try to find the original unredacted program. Please comment on the ...
5k 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 ...
1k views

### List all palindromic prime dates between 0000-01-01 and 99999-12-31

You know what a palindrome, a prime and a date are. Your task is to list all dates in 100 thousands of years that fulfill all three characteristics. Nevermind anything but the numbers, use the ...
2k 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 ...
1k views

### Minimise the count of prime factors through insertion

Given two positive integers A and B, return the position p that minimises the number of prime factors (counting multiplicities) of the resulting integer, when B is inserted in A at p. For example, ...
1k views

### Prime numbers between n and 2n [duplicate]

Bertrand's postulate states that there is always at least 1 prime number between n and 2n for all n greater than 1. Challenge Your task is to take a positive integer n greater than 1 and find all of ...
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, \\$...
2k views

### Is it a Pascal Prime?

It is well known that odd primes will appear in Pascal's triangle exactly twice. However, not all numbers that appear exactly twice in Pascal's triangle are prime. We'll call these numbers Pascal ...
256 views

### Form a list using prime numbers

You have been given N piles of coins. You have decided to divide each of those B1, B2, ..., BN piles among separate groups of people. The amount of people receiving coins has to be a prime number and ...
331 views

### Primes ’n’ Digits

This has no practical purpose but it could be fun to golf. Challenge Given a number n, Count the amount of each digit in n and add 1 to each count Take the prime factorization of n Count the amount ...
802 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 ...
834 views

### Decomposing into primes

Given an integer n, return the number of ways that n can be written as a list of prime numbers. For example, 2323 can be written ...
383 views

### Keep Decoding This Number!

This challenge posed an algorithm for encoding an integer n as another integer r. What follows is a succinct explanation of that ...
1k views

### First and last prime numbers with prime digits of range

Challenge For a given positive integers range, find the first and last prime number entirely composed of prime number digits, exceptionally including 0 (for the digits, a range of 0-2 should output 2-...
324 views

### Decode Factor Trees

In case you missed Encode Factor Trees, here is the definition of a Factor Tree: The empty string is 1. Concatenation represents multiplication. A number n enclosed in parentheses (or any ...
382 views

### Encode Factor Trees [duplicate]

I once saw on the xkcd fora a format for expressing numbers in an odd way. In this "factor tree" format: The empty string is 1. Concatenation represents multiplication. A number n enclosed in ...
1k views

### Repeated Digit Primes

Another sequence, another challenge.* Definition A prime p is in this sequence, let's call it A, iff for every digit ...
2k views

### Different ways of defining primes

One of my favorite definitions of the prime numbers goes as follows: 2 is the smallest prime. Numbers larger than 2 are prime if they are not divisible by a smaller prime. However this definition ...
1k views

### Do we share the prime cluster?

The prime cluster of an integer N higher than 2 is defined as the pair formed by the highest prime strictly lower than N and the lowest prime strictly higher than N. Note that following the definition ...
3k views

### Output the PPCG Prime

This is the PPCG Prime 624 digits long ...
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 ...
8k views

### The prime frog 🐸

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19... Your program should accept an integer n as input and output the ...
168 views

### Multi-Base Primes [closed]

For the purpose of this challenge, a multi-base prime is a prime which, when written in base 10, is prime in one or more bases smaller than 10 and larger than 1 as well. All single-digit primes are ...
1k views

### Primes in the prime factorisation

I saw another prime challenge coming by in PPCG, and I do love me some primes. Then I misread the introductory text, and wondered what the creative brains here had come up with. It turns out the ...
9k views

### The prime ant 🐜

The "prime ant" is an obstinate animal that navigates the integers and divides them until there are only primes left! Initially, we have an infinite array A containing all the integers >= 2 : ...
2k views

### How many unique primes?

One way to represent a natural number is by multiplying exponents of prime numbers. For example, 6 can be represented by 2^1*3^1, and 50 can be represented by 2^1*5^2 (where ^ indicates exponention). ...