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
0answers
90 views

Computation of primality

I believe I have achieved computation of primality! That is, the computation of prime numbers. The code I am about to post will give you every prime there is, in order, starting with 2. Can we call ...
1
vote
0answers
97 views

Calculate and make a database of prime numbers

I recently created a program for finding a prime number. It's working great and doing it very fast but I was wondering if you can help me make it calculate the prime numbers faster. ...
0
votes
1answer
649 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/...
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....
0
votes
1answer
347 views

Finding the first 10 million primes

I'm trying to find the first 100 million primes and am trying to find the most efficient way to do it. Can I get some advice on how I could improve this? ...
0
votes
3answers
1k views

Sum of maximum primes as another prime below a million

This is a project Euler Problem #50. Here is my solution with the problem. ...
0
votes
1answer
90 views

A faster way to compute largest prime factor (Again, but a lot better)

I came up with this code after implementing the feedback given by @200_success. The previous one (A faster way to compute the largest prime factor) tested my patience, but still failed to give the ...
0
votes
2answers
58 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 ...
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 ...
0
votes
1answer
121 views

A non-static Sieve of Eratosthenes class, version 1

Over the years I’ve seen many C# sieves and despite their varying internals all that I have seen invariably are a static method that returns a List<int>, ...
0
votes
1answer
201 views

Review my prime factorization function. Is it complete?

This is a function designed to return all the prime factors of a given number, in sorted order from least to greatest, in a list. It relies on another function that checks if a given number is prime. ...
0
votes
1answer
41 views

Naïve Prime Factorization in Clojure Pt. 2

After my last review request, I decided to try and make a "tree" visualization, and thought that I could benefit from making find-prime-factors lazily produce prime ...
0
votes
2answers
95 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? ...
0
votes
1answer
1k views

Project Euler #50 Consecutive prime sum

I'm having trouble optimising the project euler #50 exercise, it runs for around 30-35 seconds, which is terrible performance. The prime 41, can be written as the sum of six consecutive primes: ...
0
votes
1answer
536 views

Speeding up Mersenne prime generator

I am writing a program to calculate Mersenne primes. This code works, but it is so slow: ...
0
votes
2answers
79 views

Prime conjecture [closed]

I am trying to solve this SPOJ question. ...
0
votes
2answers
6k views

Problem in calculating prime numbers in python [closed]

I'm a noob in programming. I was asked to code a program that can calculate prime numbers. So i coded as provided below. But it prints all the Odd Numbers instead of Prime Numbers. I think the Value ...
0
votes
2answers
70 views

Euler Project #3 Largest prime factor timeout

I have been recently trying my hands on Euler's Project through HackerRank and got stuck with project #3 where you have to find the Largest Prime Factor. Question: The prime factors of 13195 are 5, 7,...
0
votes
1answer
111 views
0
votes
1answer
43 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 ...
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? ...
0
votes
1answer
189 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 ...
0
votes
1answer
171 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 ...
0
votes
1answer
129 views

Calculating the prime numbers between two integers

I've wrote this code to calculate the prime numbers between two integers n and m, and I want to optimise it. ...
0
votes
1answer
2k views

Getting prime numbers between a range

I have the following code to get the prime numbers between a range of numbers. Is this the best and fastest method? ...
0
votes
2answers
213 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 ...
-1
votes
1answer
104 views

Decomposing a number into primes

I have written the following code to decompose a number into primes. The problem is that it takes so much time and I have no idea why. ...
-1
votes
1answer
420 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(...
-1
votes
1answer
23 views

prime function in a for loop using Math operations [closed]

guys I saw a function(the function is just below) that check wether a number is prime and return a value but I don't understand the operations made in the code. Can someone explain me mathematically?...
-1
votes
1answer
511 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 ...
-1
votes
2answers
295 views

Prime Number Generator

The purpose of this program is to run an infinite prime generator that won't stop unless I tell the console to stop. This is not a sieve of Eratosthenes; it stores prime numbers in an array and ...
-1
votes
1answer
145 views

Motorola 6809 Prime finder

I'm trying to make a small program which takes a number (form 1 to 1000) and shows the primes between 2 and that number. Right now I have a quite functioning program (except a couple of bugs), but the ...
-1
votes
2answers
74 views

Project Euler problem # 3 is this the most efficient approach in Python or can I do better?

The problem statement: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? This code takes 9 seconds!, is there a better way? ...
-2
votes
2answers
81 views

Testing primality

This method accepts an int parameter and verifies if the parameter is a prime number by trial division. It returns a Boolean value of true if it is prime or ...
-3
votes
1answer
84 views

Closest Prime Number via Letters [closed]

I'd like this code to be optimized and factorized, along with, perhaps, re-making it so it's more readable via introducing better functions and minimizing the lines needed for it to be human-readable (...
-4
votes
1answer
62 views

Printing a prime normalized sequence

The program below generates a prime normalised sequence. So, what happens is this: It asks you to provide a number within a range. Program then calculates a factor which is inverse of product of all ...
-5
votes
2answers
590 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 ...
-5
votes
1answer
46 views

Find pair of adjacent prime numbers in a two-dimensional array

Does anybody know how to find pair of adjacent prime numbers in two-dimensional array, quicker than this? I'm talking especially about this part which looks for adjacent numbers not about function ...