# Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

268 questions
Filter by
Sorted by
Tagged with
2k views

### Palindromic Primes without 11

Every palindrome with an even number of digits is divisible by 11, so 11 is the only [palindromic prime] with an even number of digits. - David Wasserman, OEIS I learned this today the manual way, ...
738 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 ...
3k views

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 ...
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 ...
2k views

### Additive Primes amongst first x Primes

Definition of Additive Primes: Numbers which have exactly 2 divisors are called Prime numbers. Numbers which are prime and their sum of digits is also a prime number are called Additive Primes Task:...
657 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 ...
2k views

### Find Recursively Prime Primes

The Recursively Prime Primes is are sequence of primes such that p(1) = 2 p(n) = the p(n-1)th prime Here is an example of how one might calculate the 4th ...
857 views

### Smallest multiplier that reveals a factor of a semiprime

Given a semiprime N, find the smallest positive integer m such that the binary representation of one of the two factors of N can be found in the binary representation of N * m. Example Let's ...
308 views

### Closest Woodall Prime

A Woodall Prime is a prime which can be calculated, given a positive integer n, with n * 2^n - 1. Your task is to, given a ...
2k views

### Smallest n-digit prime containing only these digits

You will need to generate the smallest prime with n digits, and it will only contain digits specified in the list k. Examples: ...
1k views

### Prime Divisor Table

Intro Something I've played around with in recreational mathematics has been construction of a divisor table to visually compare/contrast the prime divisors of a set of numbers. The set of input ...
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 ...
4k views

### The program that will find the next prime number

Intro: You accidentally corrupted the flow of time with a device you made for fun, that turned out to be a time machine. As a result, you got pushed to the far future. You realized that computing, ...
897 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 ...
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'...
2k 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 ...
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 ...
255 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 ...
289 views

### Negative XOR primes

About a year ago you were asked to find the XOR primes. These are numbers whose only factors are 1 and themselves when performing XOR multiplication in base 2. Now were are going to spice things up ...
3k views

### Smallest Prime with a Twist (A068103)

The task at hand is, given a number n, find the smallest prime that starts with AT LEAST n of the number ...
5k views

### Determine whether a number is 2017-friable without primes in your source code

Out of all the years I've been making this challenge, 2017 is the first year that's been a prime number. So the question will be about prime numbers and their properties. Your task is to produce a ...
341 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 ...
732 views

### Every prime bit must alternate

A program is bit primed if bits in prime positions must alternate between zero and one, starting with one. For example, this is a template for a bit primed program with [0..47] bits. ...
5k views

### Coprimes up to N

Given a number n >= 2, output all the positive integers less than n where gcd(n, k) == 1 (...
2k views

### Calculate the prime factors

We had a prime factorization challenge a while ago, but that challenge is nearly six years old and barely meets our current requirements, so I believe it's time for a new one. Challenge Write a ...
3k views

### Is it a Mersenne Prime?

A number is a Mersenne Prime if it is both prime and can be written in the form 2n-1, where n is a positive integer. Your task is to, given any positive integer, determine whether or not it is a ...
899 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 ...
199 views

### The Primitive and Basic Numbers

Your task is to generate the "Primitive and Basic" numbers, which are made like so: Start with 110. Take the digits of its base-1 representation (110 = 11) and interpret them as base-2 digits. This ...
513 views

### Every nth prime number up to 8675309

Read this if you're confused. Challenge: The goal of this code-golf is based around the number 8675309... Your goal is to print out every prime number from 2 to ...
1k views

### Generate n-ary numbers

A secondary number is a positive integer whose prime factors (without multiplicity) are all less than or equal to its square root. 4 is a secondary number, because ...
869 views

### Print the missing primes

The Task Write a program or function that, when passed a numerical input x, prints or returns the primes beneath the square root of ...
334 views

### Nostalgic prime number generator [closed]

Remember the good old days when opening a simple document or web page was painfully slow as it hogged all the meager resources your computer had? And today, doing the same is even slower, despite your ...
2k views

### Finding The nth Prime such that the prime - 1 is divisible by n

Problem The goal is as the title says to find the nth prime such that the prime - 1 is divisible by n. Explanation Here is an example so you understand the question, this is not necessarily the ...
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: ...
1k views

### Primenary Strings

A Primenary (binary-prime) string is one which, when written as a binary grid, every row and column has a prime total. That's quite a vague explanation, so let's break it down with a worked example.....
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 ...
693 views

### Goldbach partitions

The Goldbach conjecture states that every even number greater than two can be expressed as the sum of two primes. For example, 4 = 2 + 2 6 = 3 + 3 8 = 5 + 3 ...
2k views

### Sieve of Eratosthenes, Step by Step

Given a number N, draw a left aligned NxN board of numbers, leaving 1 blank (as a space) (I will show diagrams with N=5) ...
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: ...
2k views

### Compute the Mertens function

Given a positive integer n, compute the value of the Mertens function M(n) where and μ(k) is the Möbius function where μ(k) = 1 if k has an even number of distinct prime factors, -1 if k has an odd ...
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 ...
2k views

### Prime counting function

Introduction The Prime Counting Function, also known as the Pi function $\pi(x)$, returns the amount of primes less than or equal to x. Challenge Your program will take an integer x which you ...
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 ...
6k views

### Compute the Carmichael function

Task description In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n. ...
4k views

### Can the number reach 1 by repeatedly subtracting the largest prime less than it?

Challenge: Given a number, take the largest prime strictly less than it, subtract it from this number, do this again to this new number with the biggest prime less than it, and continue doing this ...
615 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 ...
1k views

### Excessive Integers

For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where ...
1k views

### Variable Prime “Twins”

I am 2/3 twins with my brother, i.e. born on the same day of the same month but twelve years later. When I was 5, he was 17, both primes; the last pair of ages we can reasonably count on is [71, 83] ...