Linked Questions

-3
votes
2answers
303 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 ...
192
votes
287answers
44k 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 ...
32
votes
40answers
5k 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 ...
28
votes
41answers
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 ...
27
votes
42answers
3k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between a and b (inclusive). Input a ...
22
votes
26answers
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 ...
15
votes
33answers
3k 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
21answers
32k 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 ...
26
votes
21answers
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: ...
32
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, ...
18
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
13answers
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: Where pk is the k th prime number (with p1 = 2). Examples: ...
28
votes
12answers
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 ...
5
votes
27answers
2k views

Enterprise Quality Code Prime Sieve

Enterprise Quality Code! TL;DR Answers will consist of a full program (of length < 30k) prints the the first N Prime numbers (as a base 10 representation without leading zeros unless the chosen ...
11
votes
16answers
2k views

Prime numbers in large number

Given a large number (in base 10), such as 1234567891011121314151617, find prime "subnumbers" in it. A prime "subnumber" is a consecutive sequence of digits (taken from the input), which represents a ...

15 30 50 per page