Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If every prime factor is prime number then, how 1️⃣ is a prime factor? ⚠️ ⚠️ ⚠️ #7

Open
2 tasks done
artbindu opened this issue Feb 8, 2023 · 4 comments

Comments

@artbindu
Copy link

artbindu commented Feb 8, 2023

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.
  • 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 returning 1

This is my code:

from primePy import primes

n = 1
print('lowest prime factor', primes.factor(n))
print('all prime factors: ', primes.factors(n))

Output:

lowest prime factor 1
all prime factors:  [1]

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.

@artbindu
Copy link
Author

artbindu commented Feb 8, 2023

I just saw one issue there which is resolved:
#5

But still it's reproducing

@artbindu
Copy link
Author

artbindu commented Dec 5, 2023

Completely freezing compilation when we pass 0 or Negative Value by mistack.

It should return None or some valid message.

@artbindu
Copy link
Author

artbindu commented Dec 5, 2023

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 []

@artbindu
Copy link
Author

artbindu commented Jan 9, 2024

Issue is fixed in this branch
https://github.com/artbindu/primePybugFixed

Commit:
artbindu@fe9aa90

Please verify once @janaindrajit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant