Questions tagged [primes]

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.

Filter by
Sorted by
Tagged with
6
votes
2answers
591 views

General primality test in C++

I have this code, which I think can be optimized even more, but I can't think of a way of optimizing the main loop to make it faster and more comprehesive. Here's the code: ...
10
votes
3answers
366 views

SSE loop to walk likely primes

This is a continuation of a discussion that was started here. While there are some interesting points there about instruction timing and latency, it is not necessary to read that Question to ...
1
vote
1answer
56 views

Basic Sieve of Erosthenes

This is a basic command line program that, given a number, returns a list of primes up to and including that number. Also handles a lack of command line arguments and non-number arguments. I ran into ...
2
votes
0answers
90 views

Improved Atkin-Bernstein sieve for generating primes

This is a class from my personal code library, and from a package which deals with integer sequences. It implements an interface ...
3
votes
2answers
2k views

Prime number generator in C

I have to print numbers between two limits n and m, t times. I created ...
2
votes
2answers
2k views

Number of prime numbers in a given range

I've written a method that should return the numbers of prime numbers in a given range: ...
0
votes
2answers
45 views

Accumulate the charAt(*) for each n

This is a helper function, along with three others. It should be called as a .filter(); to return only prime numbers. It is for one of the exercises at FreeCodeCamp....
2
votes
1answer
581 views

Project Euler 46: Finding a counterexample to a Goldbach conjecture

I'm working on problem 46 from project euler: It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. ...
7
votes
1answer
541 views

Finding circular primes

I'm coding for a project euler question and every now and then, the question will demand a program that is efficient even when doing brute force. Which I struggle with. Below is a piece of code for ...
2
votes
2answers
1k views

Prime Factorisation in Swift

I made a playground to try find prime factors of any given number, and it works, and I'm happy with the first function, even if not correctly named - I don't know what to name it. My main need for ...
2
votes
1answer
217 views

Check where the integers are Tprime or not

The objective of the code is to check the given inputs are tprime or not. Example: ...
10
votes
6answers
3k views

Determine if number is a prime number

I made a function that takes an argument x and returns True if x is a prime number and ...
2
votes
2answers
145 views

Prime Number related class design

I am creating a class which should contain all the methods related to Prime numbers. Now in that I have to implement a method isPrime() to check the primality of a ...
14
votes
4answers
1k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t ...
6
votes
1answer
140 views

Lucas Lehmer Primality Test

I have coded the Lucas-Lehmer primality test following Wikipedia's description. I used the mod 2^n - 1 suggested in the article but was wondering if there were any ...
5
votes
3answers
1k views

Maximum path sum in a triangle with prime number check

I was given this algorithm task: You will have a triangle input below and you need to find the maximum sum of the numbers according to given rules below; You will start from the top and move ...
2
votes
2answers
231 views

Project Euler Problem 7: 10,001st prime

The problem statement is as follows By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10,001st prime number? My code that ...
3
votes
2answers
495 views

Ugly Number - Java

I am implementing an Ugly number implementation in Java and need help to optimize the code. Maybe reduce space and/or time complexity. Ugly numbers (as per problem statement): positive numbers whose ...
4
votes
2answers
251 views

Functionaly Finding Prime Factors with Multiplicity

I am quite new to Haskell so any suggestions are welcome, also I noticed that it works quite slow even for something like ...
5
votes
1answer
89 views

Learning F# with Prime Factorization

In my quest to learn F#, I implemented Prime Factorization. First, the code: ...
0
votes
1answer
166 views

Project Euler # 3 in Haskell: largest prime factor of some number

The program works, but is extremely slow. Project Euler problem 3 Problem: What is the largest prime factor of the number 600851475143? ...
2
votes
1answer
933 views

Rust: Prime numbers

A first attempt to implement the Sieve of Eratosthenes to find all the prime numbers from 2 up to a given number resulted in this brute force algorithm. A user pointed out, that this is in fact not ...
2
votes
1answer
87 views

Optimised Python Code gives TLE for PRIME1

PRIME1 is a codechef problem which states: Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers. ...
3
votes
2answers
137 views

CodeChef PRIME1 problem in Python

PRIME1 is a CodeChef problem which states: Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers. ...
13
votes
3answers
14k views

Generate nth prime number in Python

Today I had an interview, where I was asked to solve this problem: Generate nth prime number. Given a signature below, write python logic to generate the nth prime number: ...
1
vote
1answer
154 views

Print all prime numbers to <stdout> within the threshold boundaries with the range provided by user

I found this exercise on the web and this is my attempt to solve it. Things i'm interested the most from this coding review Naming convention I don't comment the code that much. For you to faster ...
8
votes
1answer
483 views

Prime sieve for all primes up to a number

As a beginner to C++, I wanted to make something using what I was learning, so I did this to learn about arrays. This implements the Sieve of Eratosthenes to find the primes up to a limit. I didn't ...
11
votes
2answers
723 views

Breadth First Search to find connected primes

I've been working through the British Informatic Olympiad's 2016 Paper, and I've been struggling with some of the larger cases for question 3, specifically the larger cases on the mark scheme (the 3 ...
0
votes
1answer
186 views

Finding prime numbers performance

I am writing an app that finds prime numbers within a specified range. Currently i am updating almost every part of the app and i have also changed the way i find prime numbers. The problem is that ...
5
votes
1answer
566 views

Sieve of Atkin in Python

I recently implemented the Sieve of Atkin prime generating algorithm in Python. Though I know the term "pythonic" isn't exactly set in stone, I can tell that my program doesn't quite take advantage of ...
8
votes
3answers
287 views

Project Euler+ #35 - Summing circular primes less than N

Overview The following code is a solution for a Project Euler+ problem on Hackerrank. A circular prime is a prime number whose rotations are also prime. For example, 197 is a circular prime since it ...
3
votes
3answers
1k views

Find next prime

I wrote small app finding next prime number starting from number passed as argument: ...
23
votes
2answers
5k views

Simple twin prime finder

I'm really new to coding so I'm looking for a bit of feedback on this twin prime finder. She works pretty decent but I know it could be better. ...
4
votes
2answers
351 views

Sieve of Sundaram

Every integer can be written in the form \$2^i*v\$ where \$v\$ is odd. This algorithm generates a list of numbers that are only odd. We want to ensure that all the composite odd numbers are marked out....
5
votes
4answers
2k 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
137 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 ...
84
votes
5answers
15k 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
172 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
1answer
167 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 ...
4
votes
2answers
2k views

CodeWars: Gap in Primes

I wrote JavaScript code for finding the first two consecutive prime numbers (that doesn't have divisors except one and itself) with a specific gap between them. It works well but take too much time to ...
-5
votes
2answers
581 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
626 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/...
4
votes
2answers
751 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
580 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
556 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
1k 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....
1
vote
0answers
288 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
77 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
262 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
82 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 ...