Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
0answers
11 views

Naïve Prime Factorization in Clojure

I saw a question about prime factorization on Stack Overflow and realized I had never attempted it before. This was what I ended up with after some playing around and tweaking. I'd like improvements ...
8
votes
1answer
178 views

Find “prime polynomials” for a user's given prime, bounds, and degree

Very amateur programmer and first-time poster here. The program I wrote asks the user for a prime number, a lower and upper bound, and a degree (all of these are integers). I want to generate a list ...
-2
votes
1answer
56 views

Finding all prime factors of a number in C# [closed]

I recently wrote a function to find all prime factors of a number and I'd like to know how to improve it. I'm particularly interested in how I can redesign anything to make it more efficient, mainly ...
3
votes
0answers
43 views

A Rust crate with both `main.rs` and `lib.rs` performing primality checking

Introduction I decided to get my feet wet in Rust by going ahead an implementing a full crate with the tests, documentation, and all other accompanying stuff. This is a toy implementation of a ...
2
votes
2answers
72 views

Prime engine: generation, primality, factorization

I've just written my first C# class, so I'm looking for some feedback before I go and write more code. The goal of the code is to provide a Singleton-like class to deal with common operations on the ...
3
votes
1answer
69 views

Prime factorization in Python

Beginner programmer here. What can I improve in my code? Are there things I'm doing wrong or are there easier ways of doing what I did? ...
0
votes
1answer
46 views
2
votes
1answer
28 views

Testing a probabilistic prime-testing algorithm that may fail

I have implemented Pollard's Rho algorithm in Java. Due to the nature of it there is a small chance for it to fail (have not seen it happening yet). Since I do not ...
2
votes
1answer
63 views

Generation of products of power

Given positive integers a,b,c and limit, I want to generate all products having the form $$p^aq^br^c \leq limit$$ less than limit (where p,q,r are distinct primes). a,b and c are not necessary ...
4
votes
1answer
45 views

Euler Problem 7 (finding the 10001st prime) in Powershell

I am having issue making this code more efficient. The problem to be solved 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. ...
2
votes
2answers
74 views

Project Euler Problem 37 in Python

Project Euler Problem 37 asks: The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797,...
0
votes
3answers
88 views

Display a number as a product of its prime factors

Task: Link to original problem :https://www.spoj.com/problems/FACTCG2/ The task in this problem is to write a number in a multiplication of prime numbers separated by “...
0
votes
2answers
56 views

Finding primes from random integers

I was hoping I could get some help making my code more efficient. I'm a math major taking an Intro to Programming class, and I was asked to write a C program that generates: A text file named ...
2
votes
1answer
87 views

Program that finds prime numbers in a specific range

I'm kinda new to programming, and as a solution to an exercise, I made a program to find prime numbers in a range. It runs just right for small ranges of numbers, but for this exercise we are given a ...
1
vote
2answers
74 views

Prime factorization program

Compute the prime factors of a given natural number. A prime number is only evenly divisible by itself and 1. Note that 1 is not a prime number. My solution will catch every prime up to and including ...
3
votes
2answers
74 views

Sieve of Eratosthenes in Rust

This is a relatively simple implementation of the Sieve of Eratosthenes in Rust. The main objective is to find the \$n\$th prime quickly when \$n\$ might grow to huge numbers. ...
20
votes
3answers
3k views

Checking if a number is prime in NASM Win64 Assembly

I'm just learning Assembly. This program is a simple attempt to determine if a given number is prime or not. Any advice and all topical comments on code optimization and conventions is appreciated! ...
0
votes
2answers
52 views

Prime number generation - SPOJ

This is a program to generate prime numbers for a given range. The sieve of Eratosthenes algorithm was implemented, but still the SPOJ says time limit exceeded. Where can some optimizations be made? ...
3
votes
1answer
48 views

C++/STL Prime tuples (twin, cousin, sexy) up to the given limit

As I'm mastering STL I wrote a solution for generating all the prime tuples of the form (p1,p2) where "twin" means p2-p1=2, "...
-1
votes
1answer
293 views

For pairs of elements, count the ones whose XOR value is a sum of two primes [closed]

An array is given with 'n' Values ( n <= 10^5 ) ; we have to calculate xor of each pair of elements and count those pairs whose xor can be written as sum of two prime numbers with the same parity(...
3
votes
2answers
144 views

Calculate divisors using prime factorization

For learning purpouses I wrote a class that is supposed to find all divisors for a given integer. My class makes use of primes and prime factorization to speed things up a bit. What can I improve in ...
-1
votes
2answers
111 views

Largest prime factor function

I have written a function which finds the largest prime factor of some number. This function works but the problem is that it is too slow. For instance, when I enter 600851475143 as a parameter, the ...
7
votes
2answers
501 views

alternating Fibonacci and prime series

The task is to print the following series 1 2 1 3 2 5 3 7... The elements at odd positions are Fibonacci series terms and the elements at even positions are ...
4
votes
1answer
92 views

Prime pair set finder (Project Euler problem 60)

I made a code that can find the prime sets: 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 ...
2
votes
1answer
109 views

Are numbers prime multithreading

I'm trying to learn some multithreading and this seems like a good example, want to apply this to frustum culling later. The goal is to find prime numbers in randomly generated vector of numbers. ...
0
votes
1answer
39 views

Printing all the factors as well as the prime factors of a given number using Python 2.7.x

Okay here is my maiden attempt at programming using Python 2.7. I need help or feedback on this code: How do I know about the processing cycles this program consumes? How do I implement this idea ...
7
votes
1answer
264 views

Printing factors and prime factors of a number

I am a 46 year young newbie trying to learn programming for fun and adventure. I do this in my free time. Some very nice gentlemen on stackoverflow have sent me here. I wish that someone could review ...
3
votes
1answer
61 views

Spoj-Prime Generator

Question- Generate all prime numbers between two given numbers. https://www.spoj.com/problems/PRIME1/ My attempt- I used segmented sieve method. ...
5
votes
2answers
429 views

Euler problem 3: largest prime factor of the number

I have been trying to learn Python and just solved Euler Problem 3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I am looking ...
4
votes
1answer
123 views

Sieve of Eratosthenes in Python

This is yet another take in Python for the infamous Sieve of Eratosthenes. I am a beginner in Python so any criticism is highly appreciated. ...
10
votes
4answers
773 views

Calculating primes until a user-given value

I am new to C# programming. I wrote a little program in C# to calculate all primes until a user-given value. Ignoring the lack of computing power I wrote this program to handle theoretically very huge ...
3
votes
2answers
106 views

Show all primes in go

I'm trying to go through Adrian simple programming tasks; Elementary task 8 It's basically asking for an infinite loop to print every prime number as it finds it. Are there too many ...
3
votes
1answer
148 views

Prime number sieve in Standard ML

As practice, I have written a prime number sieve in Standard ML. It works in a pretty straightforward way: The list of known primes starts with just 2. Starting with 3, check whether each odd ...
15
votes
5answers
5k views

Python 3: Why is my prime sieve so slow?

I've implemented the sieve of Eratosthenes in Python 3 as follows: ...
2
votes
1answer
126 views

Project Euler: Find 10.001st prime

I have just started learning C# and decided to do some problems from Project Euler. I wrote a code to find 10 001st prime and I thought it would be cool optimize it to make it as fast as possible. How ...
2
votes
0answers
55 views

Haskell function to generate prime numbers up to argument [closed]

I made a function to generate a list of prime numbers using list comprehensions. Here it is: ...
2
votes
1answer
100 views

Prime numbers generator

This is a prime numbers generator class, loosely based on the sieve of Eratosthenes. It is supposed to generate a decent quantity (i.e. millions) of prime numbers. ...
1
vote
0answers
71 views

Get prime divisors of an Int32 using a wheel

I recently played around with prime factorization using a prime wheel. Much of the heavy lifting is done by the PrimeWheel class. I think the implementation is ...
2
votes
2answers
1k views

Function to check whether entire list is prime numbers

I have a prime function which accepts a list of numbers and checks if all of the numbers in the list are prime. Here is my code: ...
10
votes
4answers
1k views

Find the sum of prime numbers below 2 million

This code is trying to find the sum of prime numbers below 2 million. The code does work as intended, but it takes a very long time ( 6 minutes) for the code to execute completely. What is the problem ...
0
votes
1answer
280 views

Find primes using Sieve of Eratosthenes with Python

I was Googling for a 'correct' or 'efficient' implementation of the Sieve of Eratosthenes. I found them all more complicated than what I came up with. I am by no means a Python expert, so I was ...
11
votes
2answers
1k views

Express a number as sum of 2 primes

Problem: Given an even number (greater than 2), return two prime numbers whose sum will be equal to given number. NOTE 1: A solution will always exist. (Goldbach's conjecture) Note 2: If ...
2
votes
1answer
37 views

Display all Prime Factors from user input

The following program is written in python. Is there a more efficient way to write this program? Suggestions and criticism are welcome. You can also comment about my variable naming practices and code ...
5
votes
3answers
130 views

Outputting prime numbers in given ranges

I coded an algorithm which shows prime numbers in the ranges provided by the user. The first line states the number of test cases. Example: INPUT 2 1 10 1 5 ...
7
votes
1answer
228 views

Prime Number Generator & Efficiency

If anyone can explain to me the advantages of using things like the Sieve of Atkin over the Sieve of Eratosthenes, and how to code it (especially the Sieve of Atkin), that would be highly appreciated. ...
11
votes
2answers
2k views

Find prime factors in C++

Please review this code. ...
8
votes
4answers
143 views

Searching for pairs of integers that satisfy primality and divisibility conditions

I wrote a program in Python 3 to check all tuples of the form (s,t) where s and t are ...
4
votes
1answer
116 views

Calculate Mersenne prime numbers in MATLAB

A Mersenne prime is equal to (2^n - 1), where n is an integer. 31 is a Mersenne prime since 31 = 2^5 -1. I need to write a code that calculates Mersenne primes between 1 and 10,000. Lastly I'm not ...
25
votes
2answers
2k views

Euler's Totient Function in x86 assembly (MASM)

My task was to implement Euler's totient function, and I'm looking for any and all criticism. ...
6
votes
5answers
462 views

Python prime number checker function

I was bored, and I was watching a sci-fi show where people were starting out during a long systems check asking each other whether numbers were prime or not, sort of passing the time as they do their ...