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
1 vote
0 answers
69 views

Benchmarking an improved wheel sieve

I followed your answers for my last questions (1st 2nd) and I came up with these new versions of my codes but I face some difficulties to measure the efficiency of my code, I use chrono library to ...
1 vote
1 answer
115 views

Prime sieve for large numbers

I state that I am not an expert and that certainly the code can be improved. I made this prime number sieve to be able to handle large numbers. The basic idea is to write a number p=r+bW*k where r is ...
0 votes
1 answer
105 views

Find factors of a Mersenne number

On RosettaCode I found this C++ version of modPow (compute 2^p mod n) to find the factors of a Mersenne number. ...
0 votes
2 answers
565 views

Next level Improved Sieve of Eratosthenes

This is the next development for the Sieve of Eratosthenes algorithm, where all the multiples of 2,3 and 5 are eliminated, which will not take any memory or time. As my last question Improved Sieve of ...
8 votes
7 answers
4k views

Improved Sieve of Eratosthenes

How can I get to a perfect coding for this algorithm? I made the mathematical theorem, which is a development of the Sieve of Eratosthenes algorithm. I might use some help in coding. You can find the ...
4 votes
2 answers
124 views

Project Euler #51: "Prime digit replacements" in Rust

Problem: https://projecteuler.net/problem=51 "Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime ...
  • 424
3 votes
1 answer
70 views

Fast way to compute a^d mod n

For a Miller-Rabin primality test I need a fast way to compute a^d mod n. Where a is one of 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...
0 votes
0 answers
110 views

Sieve of Atkin C#

I don't fully understand how to make the Sieve of Atkin faster than the most ancient sieve. All implementations I found online where slower than the one I made, but still It isn't faster than ...
4 votes
2 answers
178 views

Calculate the first largest factor of 600851475143

ٍProblem description: The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29. What is the largest prime factor of the number 600851475143 ? Prime Factor: any of the prime ...
1 vote
0 answers
56 views

Count SemiPrimes task from Codility

I'm trying to solve the following exercise from codility: A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A ...
1 vote
1 answer
56 views

Clojure Prime Numbers from 1 to 1000

I am a beginner to Clojure and I made a little script that prints out every prime number from 1 to 1000. Let me know if there are any improvements that I can make: ...
1 vote
1 answer
90 views

A simple JavaScript function that does prime factorization

This is a simple JavaScript function that does prime factorization. I wrote it on an Android phone with online editor (I don't have access to computers in night time): Code: ...
2 votes
3 answers
104 views

Find prime numbers

I wanted to create a program that lists all prime numbers to a given upper bound and that will also provide the amount of primes in the set. After many hours of trial and error I was able to solve it. ...
  • 21
3 votes
0 answers
107 views

Prime number generator in lisp

My implementation is based on the incremental prime sieve described on Wikipedia. I'm relatively new to lisp so I would appreciate any comments on my coding style or on the algorithm. The below code ...
  • 315
0 votes
0 answers
41 views

calculating all prime numbers up to a given number

This program calculates all prime numbers up to n. However it runs pretty slowly. I was wondering if there was any optimisations I could make. ...
1 vote
1 answer
50 views

C code for discovering numbers with interesting/beautiful/symmetric properties

Below is a C code that generates 1000 random positive integers, for each number we check primality, palindromic property, and the square root of the sum of the digits. The purpose is to find/discover ...
  • 1,142
3 votes
2 answers
131 views

Factor 999999 numbers as fast as possible

My code finds the prime factorization of numbers, ordering the prime numbers from least to greatest. It prints a list of 999999 prime factorizations (which can be changed if you edit the function call ...
  • 131
1 vote
0 answers
157 views

MIPS-32 assembly: Determine if n is prime

I'm new to assembly and I'm learning on my own, so I'd appreciate the feedback. My priorities are correctness (on all MIPS-32 with sllv) > speed > readability ...
  • 111
2 votes
1 answer
113 views

Sieve of Eratosthenes in F#

after looking at the pseudocode for the Sieve of Eratosthenes on wikipedia I tried implementing a similar version using F#. The code runs just fine, that is, it returns all prime numbers up until a ...
3 votes
2 answers
201 views

Prime numbers iterator

I am not familiar with iterators. I am confused with the traits approach and the traditional one. I don't know which one I should use in 2021. I wrote a minimal ...
  • 933
3 votes
1 answer
505 views

Average prime number from array- Javascript

My mission is to solve this: Write a function that will take an array of numbers, and will return the average of all numbers in the array that are prime number. So far I wrote this: ...
  • 83
3 votes
2 answers
83 views

Generating prime numbers quickly in rust

I am attempting to re-implement a postponed sieve algorithm for generating prime numbers in Rust. I am able to make a solution that works, but I have to use a couple of ...
  • 151
1 vote
2 answers
86 views

Improving Project Euler code problem #10

So, I just finished Problem 10 on Project Euler, but it took about 3 to 4 minutes for my output to come out, due to bad coding, I guess, any suggestions on how could I optimize my code? Question The ...
4 votes
4 answers
171 views

My prime number generation program in Python

So I did my own take (I wrote my own algorithm) for generating prime numbers from 1 to 1000. ...
  • 51
0 votes
2 answers
114 views

My prime sieve using Python

...
  • 51
1 vote
2 answers
77 views

A function to find all the primes between two numbers whose reverse is also a prime and doesn't include palindrome, in JS

I am trying to solve a challenge in which I have to write a function that takes in two numbers as arguments and returns an array containing numbers between them which are prime and their reverse is ...
  • 113
13 votes
1 answer
314 views

Sieve of Eratosthenes in Vyxal

I'm trying to learn the golfing language Vyxal because I occasionally contribute to it, and I'm slightly ashamed I can't even use it. To do this, I started with implementing the Sieve of Eratosthenes ...
  • 499
3 votes
2 answers
281 views

Python – return list (or not?) of prime numbers between two numbers

I'm trying to learn how to write code well in Python. I've been tinkering with a function that will return a list of all prime numbers between the two parameters. This is the best I could come up with ...
1 vote
3 answers
176 views

Count prime numbers whose rotations are all prime

This code solves Project Euler problem 35: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes ...
  • 39
1 vote
3 answers
225 views

Find the 10001st prime number

Project Euler 7: What is the 10 001st prime number? I currently have this code: ...
1 vote
1 answer
49 views

Python Prime Search Slower Optimization

I have these 2 version of code. Both are looking for all primes under a certain ceiling value. The first is testing against the set of all odd numbers. The second in testing against the set of all 6k-...
2 votes
1 answer
51 views

Optimize TI-BASIC Prime Numbers Finder

I wrote a program to find all the prime numbers up to N on my TI-84, however, it is quite slow for any number above, like, 50. Are there any ways to optimize my ...
0 votes
1 answer
36 views

Function returning a vec with prime factors of number

See code below and my comment with questions: ...
2 votes
1 answer
229 views

Write a Kotlin-function isPrimeNumber

Exercise: Write a prime number-test isPrime(num: Int), which for integer m >= 2 checks, if the integer is a prime number or not. My solution: ...
  • 3,758
4 votes
2 answers
73 views

Primality Test Refactoring

I devised a new primality test isPrimeNumber() below which determines if 1000000007 is prime. It works fine but the code looks unprofessional in my opinion. Is there any way to refactor it to make it ...
  • 203
2 votes
3 answers
182 views

Why is this Segmented Prime Sieve so fast?

The idea of a prime sieve is fascinating - but it has to be segmented to increase the locality of the code if you want it to be fast. Walish's segmented_sieve.cpp (see below)showed me that it works - ...
's user avatar
7 votes
2 answers
401 views

Calculate all the prime numbers between two given numbers

I've made an application that calculates all the prime numbers between two given numbers and prints then into a .txt document... anything I can improve? ...
3 votes
4 answers
127 views

Is this an efficient/correct way to get largest Prime factor?

Is this an efficient way to get the largest prime factor of a given number? Other solutions I found involved nested algorithms. ...
  • 133
3 votes
1 answer
66 views

Prime number sequence supporting repeated iteration

I'm a long-time Java programmer, but recently I decided to give Kotlin a try. So far, I'm loving the language features, it feels much more expressive than what I'm used to. As practice, I wrote this ...
  • 163
3 votes
0 answers
89 views

Performance issue regarding Project Euler #60 in Scheme

I solved Project Euler #60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 ...
  • 151
2 votes
1 answer
483 views

Prime numbers with array and OpenMP in C

...
's user avatar
21 votes
4 answers
5k views

Why is my Sieve of Eratosthenes using generators so slow

This is my prime sieve based on the Sieve of Eratosthenes. ...
-3 votes
2 answers
271 views

Is this the fastest way of testing the primality of a number [closed]

...
4 votes
1 answer
59 views

C: Sieve of Eratosthenes and next twin prime

I am wondering if I can get some feedback for my implementation of "Sieve of Eratosthenes" and twin prime. I followed this pseudocode. Few notes: I added ...
  • 359
9 votes
2 answers
145 views

Factorize All Numbers Up to a Given Number

this post is sort of a continuation of my answer on the following question: Fast Algorithm to Factorize All Numbers Up to a Given Number. As this post explains - We need to factorize all the numbers ...
  • 576
3 votes
3 answers
241 views

Project Euler 50: Consecutive prime sum

I just finished solving Project Euler's 50th problem, but it's awfully slow. I'd like to hear your thoughts on my code's efficiency and practices. Problem Statement The prime 41, can be written as the ...
  • 31
7 votes
4 answers
437 views

Finding the first pair of prime numbers that have some specified difference

I tried printing the first pair of prime number in between a list of numbers with a particular difference. But my run time is still too high (for large range of numbers). I want to reduce the run time ...
8 votes
2 answers
319 views

Add a number to a number to be prime number in python

The program is to get the nearest prime number to a number while adding a number. I solved the problem but I wish to optimize the code. ...
  • 181
1 vote
2 answers
99 views

Calculating primes: Could this be any faster?

I've ported a prime-number calculation program from primes.pyx to C++ for benchmark purpose. Since I wrote it in C++, I thought that my program would be faster than the original. However, mine took 25....
  • 113
4 votes
2 answers
230 views

Prime power mathematical problem in Python

I have a mathematical problem about prime power. A number \$x\$ can be considered a prime power if \$x = p^k\$ where \$p\$ is a prime and \$k\$ is a non-negative integer. For example, \$81\$ is a ...

1
2 3 4 5
14