Linked Questions

-3
votes
2answers
311 views

Shortest test for primality for byte [duplicate]

Write a function which gets as input a number (0 <= n <= 255) stored in 32-bit variable and returns non-zero integer if n ...
222
votes
327answers
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 ...
31
votes
45answers
3k 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 can ...
30
votes
51answers
5k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between \$a\$ and \$b\$ (inclusive). Input \$a\$ and \$b\$ can be taken from command line or stdin (space seperated) Assume \$1 \le a \le b \le ...
33
votes
41answers
7k views

Return the Closest Prime Number

Challenge This is a simple one: Given a positive integer up to 1,000,000, return the closest prime number. If the number itself is prime, then you should return that number; if there are two primes ...
22
votes
26answers
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 ...
16
votes
35answers
6k views

Calculate the sum of the first n prime numbers

I'm surprised that this challenge isn't already here, as it's so obvious. (Or I'm surprised I couldn't find it and anybody will mark it as a duplicate.) Task Given a non-negative integer \$n\$, ...
27
votes
19answers
3k views

Legendre's (Unsolved) Conjecture

Legendre's Conjecture is an unproven statement regarding the distribution of prime numbers; it asserts there is at least one prime number in the interval \$(n^2,(n+1)^2)\$ for all natural \$n\$. The ...
31
votes
20answers
3k views

Looks prime to me!

Figuring out whether a given number is prime, while not very complicated, is kind of hard. But making a guess doesn't need to be. Seeing whether a number is a multiple of 2 or 5 is easy - you can just ...
27
votes
24answers
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: ...
28
votes
21answers
40k views

List of first n prime numbers most efficiently and in shortest code [closed]

Rules are simple: First n primes (not primes below n), should be printed to standard output separated by newlines (primes should be generated within the code) primes cannot be generated by an inbuilt ...
33
votes
9answers
4k views

Kolmogorov-mania

The Kolmogorov complexity of a string s is defined as the length of the shortest program P that outputs s. If the length of P is shorter than the length of s, then s is said to be compressible, ...
7
votes
25answers
3k views

Generate this huge right triangle

Your task is to print out this exact text: ...
17
votes
19answers
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] ...
17
votes
16answers
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 ...

15 30 50 per page