# Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

262 questions
Filter by
Sorted by
Tagged with
10answers
809 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 ...
7answers
2k views

### Is it a prime? w/o math [closed]

Write a program or function in any language that tells if the input is a prime number. The input is a string representing a natural number in base-10. The output is one of the two strings "Prime" or "...
8answers
616 views

### The 3x3 Hexa Prime Square Puzzle

The 3x3 Hexa Prime Square Puzzle Introduction We consider 3x3 squares of hexadecimal digits (from 0 to F) such as: ...
5answers
374 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 ...
1answer
422 views

### Counting Cunningham chains

Prime numbers have always fascinated people. 2300 years ago Euclid wrote in his "Elements" A prime number is that which is measured by a unit alone. which means that a prime is only divisible by <...
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: <...
28answers
928 views

### Am I a Sophie Germain prime? [duplicate]

A Sophie Germain Prime is a prime number P such that 2P+1 is prime as well. Given a prime number as input, your task is to determine whether it is a Sophie Germain Prime. Standard Input/Output rules ...
14answers
1k views

### Composite Number Sequences

Composite Number Sequences Inspired by this question Given a positive integer n, your code must output the first n composite numbers. Input / Output You may write a program or a function. Input is ...
2answers
4k views

### Primes with a twist

Note: this is heavily inspired by this question. Task: Your task is to generate the nth prime, when each character of your program is repeated ...
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 ...
13answers
1k views

### The Tenacious Thai Calendar

In the Thai calendar the year 2017 corresponds to 2560. The Thai calendar is always 543 years ahead of the Gregorian calendar. Observant coders will note that 2560 is equal to ...
12answers
464 views

### Swap prime exponents with their neighbours

(Follow-up to my question about swapping bits with their neighbours.) Task Given a positive integer x = (2a · 3b) · (5c · 7d) · (11e · 13f)...
7answers
2k views

### What is the average of n, the closest prime to n, the square of n and the closest Fibonacci number to n?

This is a math problem which takes quite many things into question, making it rather challenging, and as you might have guessed, it's a code golf, so it should be as short as possible as well. The ...
7answers
366 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 ...
10answers
2k views

### Sieve of Sundaram (for finding prime numbers)

The Challenge Implement the Sundaram sieve for finding prime numbers below n. Take an input integer, n, and output the prime ...
1answer
427 views

### Primality Testing in Manufactoria

Background Manufactoria is a game about programming. The player must use a form of two-dimensional programming language to complete tasks. If you've never heard of it, the easiest way to learn is to ...
3answers
253 views

### The highest prime factor of neighboring numbers

I think it's easiest to explain this challenge in a sequential manner. Start with an input number N and: Find its highest prime factor Check numbers above and below N and see if the highest prime ...
4answers
843 views

### Crazy Librarian's Interesting Prime Permutation Index Number Generator

You saved the day with your prime sequence code, and the math teacher loved it. So much so that a new challenge was posed to the librarian (a/k/a, your boss). Congratulations, you get to code the ...
28answers
2k views

### Array Factorization

Given an array of positive integers, output a stable array of the distinct prime factors of these integers. In other words, for each integer in the input in order, get its prime factors, sort them, ...
7answers
4k views

### Determine if a number is prime without using arithmetic [duplicate]

Write a program which determines if a given number is prime. The catch: No digits or arithmetical operators. This means: No digits from 0 to ...
7answers
715 views

### Transposed, primes, oh my!

The task is simple: your program reads an integer as an input, and prints whether it is a prime or not. You can print "yes/no", "true/false" or anything what unambiguously identifies the result. The ...
10answers
1k views

### Primes numbers with prime index

Write a program or function that outputs/returns the first 10000 prime-indexed prime numbers. If we call the nth prime p(n), this list is ...
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-...
14answers
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, ...
17answers
510 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'$ ...
8answers
2k views

### These Primes of Mine Are Always Solid Lines

Let's create a N×N grid of spaces and underscores that can be used to visually determine if a number is prime. (N may be any positive integer.) This grid has three simple rules: The nth column ...
11answers
897 views

### The negative order integer challenge, but it's Prime Time!

Im talking about this question, take a look at it if you are a bit confused. Main Task Your task is to output concatenated integers, in decreasing order, but increasing the maximum integer everytime ...
9answers
833 views

### Pair-golfing Twin primes and the Collatz sequence

This is a new kind of challenge inspired by the Recover the mutated source code problem. You should write two programs or functions both in the same language. The first one should solve Task #1 and ...
8answers
359 views

### Dense Number Sequence

OEIS: A167171 A dense number is a number that has exactly as many prime divisors as non-prime divisors (including 1 and itself as divisors). Equivalently, it is either a prime or a product of two ...
5answers
179 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 ...
16answers
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 ...
16answers
693 views

### Divisor sum from prime-power factorisation

The task is to compute the divisor sum of a number given its prime factorisation. Input Two arrays (or something equivalent) of length n, one containing the prime factor and the other containing the ...
12answers
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 ...
4answers
225 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 ...
6answers
612 views

### Products of Consecutive Primes

As of time of submission to the sandbox, I had 17017 reputation, which you will all be able to factorise as 7×11×13×17, a product of 4 consecutive primes. Please write a function or program to output ...
10answers
992 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, ...
6answers
651 views

### Calculate Exponents bit by bit

Your task is to slowly calculate exponentiation, with the following steps: Given two inputs (in this example, 4 and 8), you must calculate the exponentiation by calculate the equation bit by bit. You ...
11answers
422 views

### Print/Output all positive numbers in which every multi-digit substring in its decimal representation is also prime.

Task Your task is to print or output all positive numbers in which every multi-digit substring in its decimal representation is also prime. If the number has at least 2 digits, this would imply that ...
3answers
478 views

### Priming a Pristine World

Heavily inspired by Programming a Pristine World. Also closely related to this challenge. Let's define a pristine prime as a number which is itself prime, but will no longer be prime if you remove ...
5answers
296 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 ...
2answers
395 views

### Right and tfeL truncatable primes

A right-truncatable prime is a prime where every prefix is a prime (in base 10). A left-truncatable prime is exactly the opposite, where every postfix is a prime (primes that start with 0 aren't ...
4answers
455 views

### Calculate the p-adic norm of a rational number

Calculate the p-adic norm of a rational number Write a function or a program, that takes 3 integers m,n,p (where p is a ...
24answers
2k views

### Cops and Robbers bowling (Robbers)

Robbers' Thread In this challenge, your goal is to crack some code written by the Cops (their code is here) by modifying it. You have cracked their code if: Your modified code has a maximum ...
18answers
1k views

### Find prime factors [duplicate]

A whole program to find the prime factors of a given number. The number will be given on standard input.
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 ...
4answers
854 views

### Anagramming Code

Let's try this again. The object of this contest is to make two pieces of code that are anagrams of each other (the two must contain the same bytes in a different order), and they will do the ...
10answers
788 views

### Generating Fermat primes

Given a number n, print the nth prime Fermat number, where the Fermat numbers are of the form 22k+1. This code should theoretically work for any n (i.e. don't hardcode it), although it is not expected ...
3answers
233 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 ...
11answers
3k views

### List Sophie Germain primes

The Question A Sophie Germain prime is a prime p such that 2p+1 is prime as well. For example, 11 is a Sophie Germain prime because 23 is prime as well. Write the shortest program to calculate Sophie ...
2answers
560 views

### The Prime Grid Game

I had fun solving this, so I offer this golf challenge. The objective of this golf is to find the largest prime number that can be constructed using the given instructions. You should accept 3x3 ...