# Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

308 questions
Filter by
Sorted by
Tagged with
3k views

### Print the nth prime that contains n

This question will be a twist on finding the nth prime number. Challenge You must write a program that will take one input n, ...
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 ...
1k views

### Is it really a comcoin?

Very interesting background Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use ...
2k views

### Primes in Different Bases

Challenge: You are given a base 10 number. For each base from 10 counting down to base 2: Take the original input number as a base 10 string, and remove any digits of the number which are invalid ...
228 views

### Ponderous primality testing [closed]

One of my favorite algorithms was posted on Stack Overflow as an answer to What is the fastest way to generate prime number recursively?. In pseudocode: Nathan's algorithm ...
590 views

### Ravenity of Cube Distance Numbers

Inspired by this Numberphile entry Background The cube distance numbers of an integer n are defined here as the set of integers that are x³ distance away for a given x. For a simple example, with <...
2k views

### A curious prime fraction formula

Given a positive integer $n$ output the integers $a$ and $b$ (forming reduced fraction $a/b$) such that: $$\frac a b = \prod ^n _{k=1} \frac {p^2_k - 1} {p^2_k + 1}$$ Where $p_k$ is the $k$...
1k views

### Stuffing primes in a box

Your task is write a program or function that can fill a given rectangle with prime numbers. The width and height of the ...
13k views

### Calculate the number of primes up to n

π(n) is the number of primes less than or equal to n. Input: a natural number, n. Output: π(n). Scoring: This is a fastest-code challenge. Score will be the sum of times for the score cases. I ...
3k views

### That's a prime... almost

If you've ever learned about primes in math class, you've probably have had to, at one point, determine if a number is prime. You've probably messed up while you were still learning them, for example, ...
250 views

### Cyclic prime number program generator

Challenge Your submission should consist of 2 or more programs each written in distinct languages. They can be arbitrarily numbered from 1 to k. Each program <...
10k 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 ...
4k 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 ...
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 ...
330 views

### Return prime factorization of a number [duplicate]

Yes, this is old and probably very simple, but I really want to be mindblown by things that I thought were obvious, so here's the challenge: You're given a positive integer as the input and you need ...
2k views

### Find the XOR Primes

In this challenge posed by xnor, we were asked to implement XOR multiplication. In this challenge the goal is to find the first n XOR primes. XOR primes are very ...
1k 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 ...
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: ...
597 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 ...
2k views

### Find the largest gap between good primes

Following the fine tradition of questions such as Find the largest prime whose length, sum and product is prime , this is a variant on a largest prime challenge. Input Your code should not take any ...
2k 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 ...
1k views

### Calculate the Kronecker symbol

Relevant links here and here, but here is the short version: You have an input of two integers $a$ and $b$ between negative infinity and infinity (though if necessary, I can restrict the range, ...
885 views

### A Mapping of Primes

Recently, I have found a bijective mapping $f$ from positive integers to finite, nested sequences. The purpose of this challenge is to implement it in the language of your choice. The Mapping ...
199 views

### Find the Nth number whose only prime factors are 2, 3, 5, and/or 7 (humble numbers) [duplicate]

First post here! I recently participated in a small friendly competition and this was one of the questions: A positive integer whose only prime factors are 2, 3, 5 or 7 is called a humble number. ...
7k views

### Calculate Phi (not Pi)

No, I don't mean $\phi = 1.618...$ and $π = 3.14159...$. I mean the functions. $\phi(x)$ is the number of integers less than or equal to $x$ that are relatively prime to $x$. $π(x)$ is ...
549 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 ...
887 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 ...
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.,...
2k 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 ...
1k views

### Primes of Ulam's Spiral

Ulam's spiral is a truly fascinating, yet puzzling, topic in mathematics. How it works in detail can be found here, but a short summary can be explained as so: I start off by writing a one, then I ...
1k views

### Crazy Librarian's Arithmetic Sequence of Primes

Well, the librarian caught you cheating at your job by using your sorting algorithm, so now you're being punished. You've been ordered to create some code so the librarian can impress the object of ...
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 ...
503 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 <...
349 views

### Primes, as efficiently inefficient as possible [duplicate]

Write a program that tests if a number n is prime by checking that none of the integers between 2 and ...
55k views

### Is this number a prime?

Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in ...
2k views

### 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 through STDIN or ...
2k views

### Fond Memories of Past Primes

Consider a prime number p, written in base 10. The memory of p is defined as the number of distinct primes strictly less than p that are contained as substrings of p. Challenge Given a non-negative ...
6k views

### A naturally occurring prime generator

There are quite a large number of prime generating functions. Pretty much all of them are constructed and are based on the sieve of Eratosthenes, the Möbius function or the Wilson's theorem and are ...
356 views

### Puzzle: Factor these 256-bit semiprimes [closed]

Challenge Write a program to factor this set of 10 numbers: ...
757 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 ...
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 ...
3k views

### Prime Nerd Sniping Pattern

Longest day of the year - here's something to waste the extra time... Overview Note this is not a popularity contest and not a graphical output challenge - you are only required to output a string ...
2k views

### Recursive Prime Factorization [duplicate]

Your job is to take the prime factors of a number taken from input (omitting any exponents equal to 1) then take the prime factors of all of the exponents, and so on, until no composite numbers remain;...
304 views

### Number of ways to sum [1..n] with [n+1..2n] such that each sum is prime

Let $n > 0$. Let $X = 1, 2,...,n$ and $Y = n+1, n+2, ..., 2n$. Define $a(n)$ as the number of permutations $p$ of $Y$ such that every element of $X + p(Y)$ is prime. For example: <...
4k 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 ...
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 ...
990 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 ...
799 views

### Self-shortening Prime Tester

Let's get right in to it. Your challenge is to make a program that does these things depending on its input: If the input is a number, output "Prime" if the number is a prime number and &...
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 ...