All Questions
25 questions
4
votes
1
answer
564
views
Prime factorization algorithm by using the multiprocessing module of Python
I may introduce a Python code of prime factorization which is from my personal project that I'm working on.
...
4
votes
4
answers
221
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.
...
1
vote
1
answer
54
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-...
6
votes
2
answers
104
views
Finding consecutive primes matching p, p + 4, p + 6, p + 10, p + 12, p + 16
Someone asked about this question on the main StackOverflow. The full question is:
Given a value N, find p such that all of ...
2
votes
2
answers
348
views
Finding the nth ugly number
I'm trying to optimize my solution to this LeetCode problem:
Write a program to find the nth super ugly number.
Super ugly numbers are positive numbers whose all prime factors are in
the ...
12
votes
3
answers
5k
views
Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) ...1748 Euler
I wrote this code to show that my reddit post is correct.
After the first two terms, the signs are determined as follows: If the denominator is a prime of the form 4m − 1, the sign is positive; if ...
6
votes
1
answer
921
views
Decompose any number to its prime factors raised to their respective powers
A simple code which takes the given number as input and gives all of its prime factors raised to their respective powers. It works well up to 10⁶; after that it slows down greatly for some numbers. ...
5
votes
2
answers
1k
views
Prime Number Generator (6n + 1 or 6n - 1)
This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares ...
14
votes
4
answers
2k
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 of test cases ...
5
votes
1
answer
1k
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 ...
7
votes
4
answers
1k
views
Python Prime Testing
This code seems surprisingly fast at checking if a number is prime.
...
5
votes
1
answer
911
views
Number of divisors of a factorial
I was solving the DIVFACT problem from Sphere Online Judge:
Given a number, find the total number of divisors of the factorial of the number.
Since the answer can be very large, print the answer ...
9
votes
6
answers
4k
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 ...
7
votes
2
answers
913
views
Counting Fermat witnesses and liars
We were asked to implement a program that calculates the number of Fermat witnesses and liars for odd numbers greater 1. This involves Fermat’s little theorem.
Fermat’s little is used to identify ...
3
votes
2
answers
216
views
Evaluating f(N,R) mod(m)
The goal is to find \$f(n,r)\mod(m)\$ for the given values of \$n\$, \$r\$, \$m\$, where \$m\$ is a prime number.
$$f(n,r) = \dfrac{F(n)}{F(n-r) \cdot F(r)}$$
where
$$F(n) = 1^1 \cdot 2^2 \cdot 3^...