Open artbindu opened 1 year ago
I just saw one issue there which is resolved: https://github.com/janaindrajit/primePy/issues/5
But still it's reproducing
0
or Negative Value
by mistack.None
or some valid message.Hi @janaindrajit Can you allow me to give access to create a PR for this issue ? I already have solution for it.
#Calculates the lowest prime factor by default
def factor(num:int)->int:
'''
Parameters
----------
num : int
Input number
Returns
-------
int
Lowest prime factor
'''
if num == 1 or num <= 0:
return None
if num==2 or num%2==0:
return 2
if num==3 or num%3==0: # dakra added
return 3 # dakra added
else:
for i in range(6, int(sqrt(num))+7, 6): # dakra Primes > 3 are all either
if num%(i-1)==0: return i-1 # dakra 5 mod 6 or
if num%(i+1)==0: return i+1 # dakra 1 mod 6
# dakra saving all the tests for number which are 3 mod 6.
else:
return num
def factors(num:int)->list:
'''
Parameters
----------
num : int
Given number
Returns
-------
list
List of prime factors
'''
fact=factor(num)
if(fact) :
new_num=num//fact
factors=[fact]
while new_num!=1:
fact=factor(new_num)
factors.append(fact)
new_num//=fact
return factors
else :
return []
Issue is fixed in this branch https://github.com/artbindu/primePybugFixed
Commit: https://github.com/artbindu/primePybugFixed/commit/fe9aa90a0d2075ac8827838385be20f121834422
Please verify once @janaindrajit
We know every prime factor of a number is a prime number.
By definition, a prime factor is a prime number that divides the original number exactly and without a remainder. If a number is a prime factor, it must be a prime number.
This is the definition according to your documentation:
primes.factor(n)
returns the lowest prime factor of n.[x]
primes.facors(n)
returns all the prime factors of n with multiplicity.I am trying to find prime factor of
1
. I am surprised it's returning1
This is my code:
Output:
We know, 1 is neither a prime nor a composite number. Prime numbers are defined as positive integers greater than 1 that are only divisible by 1 and themselves, and 1 is not greater than 1.
Please resolve this issue.