Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

5
votes
0answers
216 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 ...
-3
votes
1answer
117 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 ...
29
votes
2answers
4k 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 ...
11
votes
23answers
2k 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\$, ...
16
votes
31answers
1k 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 ...
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 ...
13
votes
32answers
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: <...
13
votes
5answers
353 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 ...
19
votes
16answers
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 ...
14
votes
25answers
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 ...
10
votes
10answers
961 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 ...
15
votes
10answers
1k 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 ...
27
votes
4answers
1k 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....
11
votes
10answers
966 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, ...
-4
votes
1answer
122 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-...
12
votes
5answers
172 views

Reduced Factorization Leader Changes

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 ...
16
votes
10answers
717 views

Formerly Composite Numbers

Sequence Definition Construct a sequence of positive integers a(n) as follows: a(0) = 4 Each term ...
22
votes
20answers
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 ...
10
votes
14answers
667 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 ...
19
votes
29answers
1k 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 ...
12
votes
12answers
966 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 ...
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 ...
12
votes
14answers
977 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, ...
8
votes
20answers
959 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 ...
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, \$...
18
votes
13answers
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 ...
10
votes
3answers
229 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 ...
11
votes
5answers
293 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 ...
21
votes
5answers
758 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 ...
14
votes
10answers
791 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 ...
8
votes
2answers
345 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 ...
12
votes
16answers
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-...
10
votes
4answers
219 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 ...
13
votes
7answers
345 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 ...
12
votes
9answers
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 ...
32
votes
16answers
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 ...
10
votes
16answers
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 ...
65
votes
23answers
3k views

Output the PPCG Prime

This is the PPCG Prime 624 digits long ...
20
votes
27answers
1k views

Largest Prime Exponents

Given an integer n >= 2, output the largest exponent in its prime factorization. This is OEIS sequence A051903. Example Let ...
44
votes
22answers
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 ...
-3
votes
3answers
153 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 ...
8
votes
13answers
949 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 ...
47
votes
18answers
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 : ...
14
votes
33answers
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). ...
14
votes
14answers
1k views

Prime Powers of Primes

For the purpose of this challenge, a Prime Power of a Prime (PPP) is defined as a number that can be defined as a prime number to the power of a prime number. For example, 9 is a PPP because it can ...
19
votes
3answers
450 views

Writing rational numbers as ratio of factorials of primes

Note: this challenge has been posted on the sandbox. Introduction This challenge is inspired by 2009 Putnam B1, a problem in an undergraduate mathematics competition. The problem is as follows: ...
6
votes
4answers
546 views

Golf the pseudoprimes!

Introduction / Background In a recent discussion in the crypto chat I was challenged to discuss / help with the Fermat primality test and Carmichael numbers. This test is based on the premise that <...
14
votes
18answers
2k views

Prime Factoral Roots

Inspired by digital roots, the prime factoral root of a number is the number that emerges when you take the prime factors of a number, add them together, and repeat the process on the resulting number,...
0
votes
3answers
105 views

Prime Factorial [duplicate]

For the purposes of this question, the prime factorial of a number n is the result of multiplying all prime numbers smaller than n, and then multiplying the result by n. Your Task: Write a program ...
17
votes
10answers
1k views

Numbers with similar powers

Given an integer p > 1, find the smallest integer q > p such that the list of exponents in the prime factorization of q is the same of that of p, no matter the order or the value of the prime factors. ...