A prime number is a number that is only divisible by 1 and itself.

learn more… | top users | synonyms

5
votes
15answers
1k views

Illiteral Prime numbers [on hold]

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 ...
15
votes
19answers
934 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 numbers will give you [4, 9, 25] ...
30
votes
17answers
2k 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, and output the nth prime number whose decimal representation contains ...
23
votes
6answers
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 0. Test ...
3
votes
10answers
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 ...
16
votes
7answers
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 ...
-3
votes
1answer
154 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 bool isPrime(int n): ...
14
votes
11answers
471 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 ...
27
votes
3answers
811 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 rectangle will be the input. The output must be a list of height strings ...
43
votes
12answers
2k 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 ...
24
votes
8answers
2k 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, ...
2
votes
0answers
70 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 p, given a natural number n should ...
20
votes
26answers
7k 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 outputs the first n prime numbers. ...
19
votes
20answers
2k 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 Möbius function evaluated at n. ...
13
votes
8answers
481 views

Palindromic Prime Factors

Palindromic prime problems are pretty common, but that's not what this question is about. In this challenge, the number doesn't have to be a palindrome, its prime factors do. Task Your code has to ...
21
votes
6answers
1k 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 ...
-1
votes
3answers
153 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 ...
17
votes
9answers
732 views

Sums of prime factors

2013 has the prime factorization 3*11*61. 2014 has the prime factorization 2*19*53. An interesting property regarding these factorizations is that there exist distinct primes in the factorizations of ...
15
votes
5answers
215 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 similar to regular primes as you can ...
17
votes
8answers
693 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 ...
23
votes
11answers
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: N | Fibonacci number 1 | 1 2 | 1 3 ...
10
votes
3answers
211 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 ...
28
votes
11answers
1k 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 ...
22
votes
16answers
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 4 primes, and then compute the sum of them. ...
9
votes
6answers
668 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, but the ...
17
votes
3answers
696 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 ...
3
votes
0answers
60 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. ...
52
votes
16answers
4k 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 x that are relatively prime to x. π(x) is the number of primes less than ...
10
votes
3answers
231 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 positive prime) as input, that outputs the p-adic norm (denoted by |m/n|_p) as ...
11
votes
4answers
317 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 ...
22
votes
13answers
796 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 ...
11
votes
10answers
975 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 3, 5, 11, 17, 31, 41, 59 ... 1366661 because p(p(1)) = ...
17
votes
6answers
740 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 ...
15
votes
4answers
514 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 ...
9
votes
8answers
889 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 numbers below n. You can assume that n will always be less than or equal ...
10
votes
0answers
237 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 ...
-1
votes
6answers
204 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 n-1 (inclusive) divide n (you must use this algorithm!). The input to STDIN should be an integer n ...
101
votes
165answers
20k 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 ...
12
votes
13answers
806 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 ...
28
votes
9answers
1k 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 ...
40
votes
12answers
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 ...
-7
votes
7answers
243 views

Puzzle: Factor these 256-bit semiprimes [closed]

Challenge Write a program to factor this set of 10 numbers: 15683499351193564659087946928346254200387478295674004601169717908835380854917 ...
11
votes
15answers
544 views

Divisor sum from prime-power factorisation [contest closed]

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 ...
19
votes
12answers
2k 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 ...
16
votes
2answers
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 ...
8
votes
7answers
789 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 ...
7
votes
3answers
259 views

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

Let n > 0. Let X = [1..n] and Y = [n+1 .. 2n]. Define a(n) as the number of permutations p of Y such that every element of X + p(Y) is prime. For example: n = 2 X = [1,2] Y = [3,4] p0(Y) = [3,4] ...
8
votes
11answers
1k 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 ...
22
votes
3answers
658 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 ...
20
votes
2answers
498 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 coefficient) multiplied by a nonnegative ...