Primes or prime numbers are numbers which are divisible only by themselves and one, starting with 2, 3, 5, 7, 11.... They are commonly used in encryption and hashing algorithms.

learn more… | top users | synonyms (1)

1
vote
0answers
17 views

Find the nth prime number

It's a long time since I've written a Sieve of Eratosthenes (about 3 decades, I think, in ZX Basic). So I decided to revisit in the light of experience. Rather than allocating a vector of unknown ...
6
votes
2answers
109 views

Find prime factors and reverse strings

I'm currently taking an introductory course to Bash at my university, and was hoping to get some peer-review from whoever might have some time. Full disclosure: the quality of the code isn't ...
61
votes
5answers
10k views

Load fifty million integers as quickly as possible in Java

I am working my way through Project Euler. Many of the problems deal with prime number calculations: this is the type of code that can be extracted into a separate class and reused. While calculating ...
4
votes
1answer
37 views

Waring's prime number conjecture

This is from Wikipedia: In mathematics, Waring's prime number conjecture is a conjecture in number theory, closely related to Vinogradov's theorem. The conjecture is named after the English ...
0
votes
0answers
23 views

Scala implicit conversion to add methods to Int

I started learning Scala, and like most functional languages, things get messy pretty quickly for a beginner. Here I have built a wrapper class for Ints so that I ...
-5
votes
2answers
57 views

Finding the largest prime factor of a 12 digit number [closed]

I created this using C++ and this gives the largest prime factor of a number.But my problem is if I try to find the largest prime factor of a very large number (12 digit number) it gives an error or ...
0
votes
1answer
58 views

Finding Wilson Primes

A Wilson prime is a prime number p such that p² divides (p−1)!+1. The first three Wilson Primes are 5, 13 and 563 and the fourth is larger than \$2×10^{13}\$. I was curious as to how much memory/...
3
votes
2answers
82 views

Prime number generator in Python

I have made a Python program that can perform some prime number functions. For example, it can produce an endless output of sequential primes. I am looking for ways to make it faster and cleaner. When ...
3
votes
2answers
70 views

My first attempt at multithreading in C# with Prime Numbers

This is my first attempt at multithreading in C#. This entire program does several things with prime numbers, but the part I'm going to post is mainly focused with printing out all prime numbers ...
5
votes
3answers
190 views

Project Euler #47: Distinct primes factors

I have solved Project Euler's problem number 47, which reads: The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The first three ...
4
votes
2answers
103 views

Get nth prime number using sieve of Eratosthenes

I am tasked with being able to find the \$n\$th prime number. I've tried to implement something like the sieve of Eratosthenes in increments of 200. The code works and returns the \$n\$th prime number....
0
votes
0answers
25 views

UVa 524 - Prime Ring

The challenge A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1,2,...,n into each circle separately, and the sum of numbers in two adjacent circles should be ...
3
votes
2answers
56 views

Number Theory Inhibitor Calculator

I've been working on generating primes and prime products quickly to aid me in my research on prime numbers, their density, etc. The answer to my Large Number Limit Extravaganza question proved to be ...
8
votes
2answers
70 views

Primality test program

I am fairly new to programming and even newer to C++ but I am currently in a class for scientific computing, and our task from two weeks ago was to improve the speed of a primality test program. I ...
0
votes
1answer
53 views

Produce all multiples of a set of primes up to a certain limit

I have some Python code that generates all possible multiples and combinations of a given set of primes up to a certain limit. The code runs and does exactly what I intend it to do, now I am trying to ...
10
votes
1answer
125 views

Large Number Limit Extravaganza

I am writing a program that computes $$n-n \cdot \left(\prod_{i=1}^n (1-\frac{1}{p_i})\right)$$ which is rewritten in my code as: $$\left(1-\left(\prod_{i=1}^n(1-\frac{1}{p_i})\right)\right) \cdot ...
5
votes
1answer
101 views

Generating smooth numbers in Haskell

I wrote a smooth function that returns a list of all smooth numbers below a certain limit from a list of prime: ...
3
votes
1answer
80 views

Prime Factors (32 bits, without Sieve)

I wrote this prime factors program as a programming exercise. Any comments or constructive criticisms are welcome. One question: prime[] is an array which stores the number's prime factors and ...
1
vote
1answer
54 views

Finding numbers divisible by primes in a given range

The problem statement (Codeforces# 385C) is this: We are given a sequence of \$n\$ numbers, i.e. \$x_i\$ and \$m\$ queries to find how many of these are divisble by primes between two given numbers ...
4
votes
2answers
56 views

Simple prime number search with trial division

I made a primality tester with trial division. I'm trying to make it as fast as possible and have reached the point now where I'm out of ideas. I use the generator approach and not lists because I ...
1
vote
1answer
53 views

Quicklyish finding primes by trial division

I ask because it seems to be taking waaaay more space/time than it should. Also, I know that if I want to be super efficient I should use Java's BitSet and a Sieve of Eratosthenes, but I wrote it like ...
5
votes
2answers
86 views

FASM assembly: Write a program which checks if a number is a prime number

Coming from high-level languages like PHP and JavaScript, I'm doing an Assembly course on Udemy. Yesterday I tried to implement the following task: Write a program that takes a number m as input, ...
8
votes
3answers
847 views

Project Euler Problem 35: counting circular primes below 1 million

Project Euler Problem 35 asks: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. How many circular primes are there ...
1
vote
1answer
56 views

Prime factorization - C

After learning prime factorization today, below is the C code written, ...
-1
votes
1answer
107 views

Largest prime factor of a given number

I'm solving Problem 3 in Project Euler: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? Most answers I found made use of array to ...
3
votes
3answers
143 views

Prime factoring function using recursion

As a programming exercise, I decided to make a prime factoring function using recursion: ...
2
votes
2answers
64 views

Infinite prime generator

This code acts as an infinite generator of prime numbers. As new prime numbers are found, they are added to a set. Then, a number x is found to be prime if none of the numbers in the prime set are ...
5
votes
2answers
209 views

Yet Another, Another Prime Generator

Yes, I realize there are many, many, many, many, many, prime generators on the Code Review SE. However, I have been unable to find any using this method for generating primes inside a vector, so I ...
1
vote
0answers
14 views

Finding the largest p-adic order of a given integer [closed]

I need to find the highest P-adic order - that is the largest power among the powers of primes in the prime factorization of an integer - of large integers . The only - and naive - approach I ...
2
votes
0answers
32 views

Mersenne Prime Checker using Lucas-Lehmer Formula

Previously I created a C# script that used trial division to check to see whether or not certain Mersenne numbers were prime. Since these numbers are so big, I employed some math shortcuts to reduce ...
12
votes
2answers
3k views

Project Euler #10 in C++ (sum of all primes below two million)

Project Euler Problem 10 asks for the sum of all the primes below two million. I'm creating a list of primes and keep checking any new number for divisibility with only prime numbers. I thought it ...
3
votes
2answers
180 views

Mersenne Primes Generator in C#

I've made a program in C# that generates Mersenne numbers starting from the current largest known Mersenne prime. It then calculates the modulo between those numbers and smaller ones starting from 3 ...
1
vote
0answers
50 views

Custom Sieve of Eratosthenes in C++

I'm trying to improve my code to find all the prime numbers within a set range as fast as possible, and I am trying to make it even faster. On my github page here, I have some optimization settings ...
2
votes
1answer
85 views

List of all prime factors of a number, including repeats

This code will return a list of the prime factors of n, and the prime factors are repeated so that the product of the list is equal to n. ...
4
votes
2answers
139 views

Sieving for prime numbers

I wanted to implement the Sieve of Erathosthenes up to int.MaxValue in C#. No object is allowed to exceed 2Gb so you can't allocate a ...
1
vote
4answers
179 views

Calculate prime numbers

This is a program to calculate the largest prime number. Are there any possible improvements in style/speed/accuracy? ...
5
votes
5answers
183 views

Project Euler #3 in C# - largest prime factor

I just started doing the Project Euler challenges and right now I'm on Challenge #3 - The largest prime factor of 600851475143. I wrote some code and tried to optimize it based on some other Stack ...
3
votes
1answer
67 views

Project Euler #58: Primes along the diagonals of a square spiral

I am working on Project Euler Problem 58: Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed. ...
6
votes
1answer
244 views

Down to Zero II

Problem : https://www.hackerrank.com/challenges/down-to-zero-ii You are given queries. Each query consists of a single number N. You can perform 2 operations on N in each move. If N=a*b (a!=1,b!=...
1
vote
2answers
92 views

Project Euler Problem #3 in Java - Largest Prime Factor

I have solved the problem and it gives me the right output when the BigInteger has the smaller value, however it kept running for more than 20 minutes with the ...
7
votes
4answers
187 views

Python Prime Testing

This code seems surprisingly fast at checking if a number is prime. ...
2
votes
1answer
66 views

Efficient Prime Sieve - Haskell

I'm new to Haskell, and am trying to learn the basics with a simple function that will calculate the list of primes up to a given value (using the Sieve of Eratosthenes). Here is my code so far, which ...
3
votes
3answers
145 views

Lucas sequence implementation

Could you suggest any improvements in this Lucas sequence's implementation: ...
2
votes
3answers
536 views

Finding out the prime factors of a number

This finds the prime factors of a number given in a variable. Is it efficient or in need of improvement? ...
3
votes
2answers
72 views

Testing Goldbach's Conjecture hypothesis

A book1 that I'm reading states Goldbach's conjecture as follows: Every even integer > 2 could be represented as a sum of two prime numbers. Every integer > 17 could be represented as a sum of ...
2
votes
1answer
60 views

Postponed Prime Sequence in Kotlin

Following my previous unbounded prime generator and a followup by Martin R, I've tested the waters in Kotlin by making an unbounded sieve. To quote Martin R's wonderful explanation of the base ...
3
votes
1answer
97 views

SICP exercise 1.28 - miller-rabin primality test part II

This is a follow-up to SICP exercise 1.28 - miller-rabin primality test. Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; ...
2
votes
1answer
83 views

Generating numbers that are a product of consecutive primes

I have implemented a correct but horribly coded solution to Project Euler Problem 293. An even positive integer N will be called admissible, if it is a power of 2 or its distinct prime factors ...
1
vote
1answer
56 views

Project Euler 12 (triangle numbers), solved using functools.reduce() and looping

I have solved problem 12 on Project Euler website, which reads: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 +...
3
votes
2answers
109 views

Simple Input Text Analysis

I've started learning java. I've written a small program I've done in C before. It's simple input analysis. If there is number, program checks if number is prime. Then write number: (value of input ...