Skip to content
Advertisement

Tag: primes

Efficient way for checking number 3^x * 5^y

I want to check if number, based on lower and upper bound, has prime divisors only 3 and 5 and number should be multiplication of power of 3 and power of 5. My current solution is this. I want to optimize it, since checking powers with for loops isn’t good way in my opinion. Thanks in advance. Based on comments

Failure to understand some prime sieve syntax

Could someone walk me line-by line through this prime sieve? I’m attempting to develop my own sieve but most of the faster ones contain syntax that I don’t understand (like the lines i’ve made comments on). Sorry if this is sort of a newbie question — also if you have any links that could help me with sieve writing they’d

Program to find the nth prime number

I wrote a code in python to find the nth prime number. The code looked fine to me, but it returns an error when I run it: It appears to me as if it is trying to say that I am referring to ptrue in the last line even though I am not. What is the problem here… Can anyone

Print series of prime numbers in python

I was having issues in printing a series of prime numbers from one to hundred. I can’t figure our what’s wrong with my code. Here’s what I wrote; it prints all the odd numbers instead of primes: Answer You need to check all numbers from 2 to n-1 (to sqrt(n) actually, but ok, let it be n). If n is

Fastest way to list all primes below N

This is the best algorithm I could come up. Can it be made even faster? This code has a flaw: Since numbers is an unordered set, there is no guarantee that numbers.pop() will remove the lowest number from the set. Nevertheless, it works (at least for me) for some input numbers: Answer Warning: timeit results may vary due to differences

Simple prime number generator in Python

Could someone please tell me what I’m doing wrong with this code? It is just printing ‘count’ anyway. I just want a very simple prime generator (nothing fancy). Answer There are some problems: Why do you print out count when it didn’t divide by x? It doesn’t mean it’s prime, it means only that this particular x doesn’t divide it

Advertisement