Questions tagged [primes]

For challenges about identifying and manipulating prime numbers

260 questions
228 views

OMG! We're Twinning! [duplicate]

Introduction We define twin primes as two natural numbers p,p+2 which both are prime. Example: 5 and ...
411 views

Counting Eisenstein primes

Introduction Eisenstein integers are complex numbers of the form a+bω Where a,b are integers, and ...
3k views

Closest 7-Distinct-Prime Product

(via chat) The OEIS entry A123321 lists the sequence of numbers that are the product of seven distinct primes. For brevity, we'll call this a 7DP number. The first few numbers and their corresponding ...
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)...
2k views

Illiteral Prime numbers [duplicate]

Your challenge is to write a program (full program, not a function), that will take an integer and output all prime numbers up to (including) the given integer. Output is any readable list containing ...
1k views

Greatest Number in a Range When The Sum of Squares of its Prime Factors are Subtracted

The formula Take for instance the number 300 The prime factors of 300 are [2, 3, 5] (unique numbers that are factors of 300 and prime) Squaring each of those ...
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 ...
212 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 ...
525 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 <...
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 ...
9k 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, ...
230 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 <...
9k 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 ...
3k 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 ...
314 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 ...
1k 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 ...
966 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: ...
475 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 ...
1k 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 ...
880 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 ...
747 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 Consider ...
83 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. ...
6k views

Calculate Phi (not Pi)

No, I don't mean ϕ = 1.618... and π = 3.14159.... I mean the functions. φ(x) is the number of integers less than or equal to <...
452 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 ...
842 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 ...
868 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.,...
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 ...
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 ...
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 <...
323 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 ...
43k 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 ...
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 ...
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 ...
5k 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 ...
341 views

Puzzle: Factor these 256-bit semiprimes [closed]

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

Recursive Prime Factorization

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;...