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)

3
votes
2answers
173 views

Printing all prime factors of a number input by the user

I just started teaching myself to code a few days ago using the Euler problems. I finished a variant of problem 3: print the prime factors of a number input by the user. I just want feedback and code ...
2
votes
1answer
80 views

Primes & Squares

Codeforces #230B Question Whether a number has exactly three factors. (i.e. 1, itself and its square root, thus squares of primes) [Time limit is 2 sec, Memory 256 MB] Input Number of testcases, n ...
3
votes
3answers
86 views

Counting the number of primes in C and C++11

I found this old piece of code that I wrote while I was learning C a while back: ...
3
votes
1answer
35 views

Writing a Rustic segmented prime number sieve

I wrote a prime number sieve in Ruby last year as part of a coding challenge, but lately I wanted to port it to Rust. I finally got around to it, but it's still intensely Rubinic. Before I take the ...
1
vote
1answer
68 views

Prime generator SPOJ problem in Python 3

I am trying to solve an SPOJ problem: print all prime numbers in a given range (as large as \$10^9\$). I have used the Sieve of Eratosthenes algorithm. But it is still slow when input is in range of ...
-1
votes
0answers
54 views

SPOJ prime generator problem in Python 3

I am trying to solve an SPOJ problem using Python 3: print all prime numbers in a given range (as large as 109). ...
-3
votes
1answer
52 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 ...
-1
votes
1answer
109 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 ...
8
votes
3answers
529 views

A reference source for primes up to 64K (for unit tests)

In order to code the tests for my number theory library (a collection of routines that proved handy for coding challenges) I needed a reference source for primes up to 2^16. I did not want to ...
7
votes
1answer
67 views

Complete factorization in ><>

Maybe a somewhat odd choice of language, but here is a program in ><> I have tried to optimize the execution time of. (Not golfing). The efficiency is measured in the number of required ...
1
vote
1answer
47 views

Prime numbers in given range

SPOJ problem PRIME1 (also found on other sites in identical form): Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are ...
6
votes
3answers
803 views

Sieve Of Erastothenes using Java

have started learning Java recently and was looking into some easy algorithms. I found the Sieve Of Erastothenes algorithm here I am trying to get better at writing good code for my solutions. Please ...
2
votes
2answers
288 views
4
votes
6answers
229 views

Read numbers until a prime is entered then print non-primes

I'm a beginner at C#. I just want to know what is the C# way to do this by its convention and a better algorithm as well. ...
4
votes
2answers
291 views

Find prime positioned prime number

This is a question from programming contest. This contest is already over. Now, all the prime numbers are arranged sequentially in ascending order. i.e:- 2, 3, 5,7...and so on. Now, your task is to ...
23
votes
7answers
5k views

Project Euler #7 10001st prime

I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
6
votes
2answers
187 views

Divisor game cheating aid

This code outputs the smallest number with more divisors than the input: ...
4
votes
1answer
54 views

Project Euler #127 abc-hits

Problem (Rephrased from here): The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$. ...
4
votes
1answer
48 views

Segmented Sieve of Eratosthenes in Scala

I'm trying to solve PRIME1 in SPOJ with the following Scala snippet: Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between ...
4
votes
1answer
108 views

Lazy prime number generator

There are multiple Project Euler problems (e.g. 7, 10) that deal with prime numbers. I decided make a reusable solution that could be used for most of them. I wrote a method to generate an infinite* ...
6
votes
2answers
101 views

Prime multiplication table

I am new to Ruby (1 year as hobby project on weekends) and solved a code challenge and it was not as good as they wanted. I want to know how i could make it better and how to make the structure ...
4
votes
2answers
117 views

Counting primes less than n

The following code was written to be a submission to this challenge on PPCG. It uses this algorithm, the Meissal-Lehmer method. I follow the Wikipedia entry pretty naively, except I tried to memoize ...
6
votes
4answers
847 views

Fast Number Factorization in Python

Here's my implementation to factorize a positive integer: ...
8
votes
2answers
434 views

Prime factorization of a natural number greater than 1

I am a math student who just started learning Java a week ago. I want to write a program in Java that return a prime factorization of any natural number greater than one. After spending some time ...
4
votes
2answers
84 views

Computing the divisor sum in bulk without division, multiplication or factorisation (SPOJ DIVSUM)

SPOJ problem #0074 DIVSUM - Divisor Summation requires computing the sums of proper divisors in bulk (200000 test cases, time limit 3 seconds): Given a natural number n (1 <= n <= 500000), ...
3
votes
3answers
206 views

Finding the 10001st prime in C#

In an effort to learn C# / improve my coding skills, I've started working on the Project Euler problems. I see that I may have been overthinking things a bit after finishing problem 7: By listing ...
1
vote
0answers
57 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. ...
1
vote
2answers
110 views

Printing all the prime numbers between two bounds

I keep getting a time limit exceeded for this solution to SPOJ Prime1. I need to print all primes within a given interval (with intervals as large as 105, and numbers as large as 109). I've tried ...
5
votes
2answers
64 views

Chen prime finder

I've written a programme to find Chen primes. A Chen prime p is a prime number where (p + 2) is either also a prime number or has two prime factors. I've got it working to the best of my knowledge: ...
9
votes
2answers
233 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
2
votes
1answer
47 views

Project Euler #7 in C: find 10001st prime using something like Sieve of Eratosthenes

I've gotten a solution for Project Euler #7 in C (find the 10,001st prime). I came up with the very simple algorithm myself (from what I can tell it's similar, if not identical, to the Sieve of ...
4
votes
1answer
51 views

Sieve of Eratosthenes in Erlang

I just started learning Erlang. Here is my crack at the Seive, based on (https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf): ...
2
votes
1answer
99 views

Project Euler Q7 - 10001st prime

The problem is (source)... 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 10001st prime number? This is my second attempt ...
2
votes
2answers
100 views

Find numbers between 1 and 10000 whose sum of digits are prime

I have the following C code that finds numbers between 1 and 10000 whose sum of digits are prime and save then to a file. ...
2
votes
2answers
53 views

Listing all primes up to a given limit

I started writing Rust by doing a simple program that will print all prime numbers until it reaches the upper bound that is provided through standard input. Here is my code ...
1
vote
2answers
46 views

Getting prime numbers, custom example [closed]

I was tasked this in class today, so the teacher could judge where our skills are. I am not an experienced C++ programmer, and I made a mistake on my sheet, so I came home and wrote this. I saw ...
4
votes
2answers
96 views

Gilbreath's conjecture in Python

I've written some code for testing Gilbreath's conjecture in python (2.x). The conjecture was shown (in the 90s) to be true up to n=1012. My code uses the primesieve module to quickly generate primes ...
3
votes
3answers
111 views

Prime Number Finder in Python

I am creating a simple program that will do three things: add up the prime numbers found within the range set by the user, print out the entire list of prime numbers, and print how many prime numbers ...
5
votes
1answer
86 views

Returns all primes p between m <= p <= n

This is my submission for the Prime Generator on SPOJ and it was accepted. Are there any improvements/changes I can make? Input: The input begins with the number \$t\$ of test cases in a ...
9
votes
2answers
119 views

Number factorization in clojure

I'm just a Clojure noob (started learning yesterday). Here is my helloworld program. It factorizes number into primes. Do you have any comments? How could I make this code cleaner and shorter? Maybe ...
7
votes
1answer
90 views

Prime factorization in F#

In the pursuit of learning F#, I have been working through some Project Euler problems. This is my solution for problem 3: ...
10
votes
3answers
125 views

Project Euler Problem 10. Sum of all primes < 2mil

I'm new to coding so I can't create complex code yet. I do as much as I can with fors and ifs, since while I know a bit about ...
3
votes
2answers
55 views

Very slow Project Euler Q3 (largest prime factor of a large number)

My code returns the correct answer for the example (highest prime of 13195 is 29), but when I test against the number in the question my code basically is too slow for my liking. The prime ...
4
votes
1answer
60 views

Finding the largest prime factor

As many people will undoubtedly recognise, this is a question in a well known series of problems that I won't name ;) It's been a long time since I've written any F# and I'm not sure I've ever come ...
3
votes
2answers
96 views

Generation of Prime Numbers

I have created this prime number generator. I want it to be as fast as possible, but I am wondering if there is a faster way (there must be). ...
8
votes
3answers
3k views

Printing all primes < 1,000,000 to a text file

It takes a long time to execute and the CPU usage for the executable is about 25% while it is executing. Any ideas on how to make this faster? primes.c: ...
4
votes
3answers
556 views

Finding prime numbers in user specified array

I have a program that searches for prime numbers in an array specified by the user. The program starts by asking how big the user wants the array to be, then asks how many threads to split the ...
3
votes
1answer
98 views

Windowed Sieve of Eratosthenes in Java

I wanted to try and use the Sieve of Eratosthenes to find all prime numbers between some arbitrary bounds 1 <= m <= n. The simple implementation of the sieve ...
7
votes
4answers
233 views

Goldbach’s Conjecture in Python

Input Format Input starts with an integer n (1 ≤ n ≤ 100) indicating the number of cases. The following n lines each contain a test case of a single even number x (4 ≤ x ≤ 32000). Output Format For ...
6
votes
1answer
85 views

Prime numbers using wheel factorial

I have written a program to find prime numbers up to a given limit using wheel factorization of 2, 3 and 5. I would like it to work above \$10^{10}\$, but its still pretty slow. What else can I ...