# PrimePy module in Python

A prime number is a natural number greater than 1 whose only factors are 1 and the number itself. 2 is the only even Prime number. We can represent any prime number with ‘6n+1’ or ‘6n-1’ (except 2 and 3) where n is a natural number.

primePy is that library of Python which is used to compute operations related to prime numbers. It will perform all the functions in less time with the help of the functions of this `primePy` module.

## Installing Library

This module does not come built-in with Python. You need to install it externally. To install this module type the below command in the terminal.

` pip install primePy `

## Functions of primePy

• primes.check(n) : It will return True if ‘n’ is a prime number otherwise it will return False.

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `print``(primes.check(``105``)) ` `print``(primes.check(``71``)) `

Output:

```False
True
```
• primes.factor(n) : It will return the lowest prime factor of ‘n’.

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.factor(``15``) ` `print``(a) ` ` `  `a ``=` `primes.factor(``75689456252``) ` `print``(a) `

Output:

```3
2
```
• primes.facors(n) : It will return all the prime factors of ‘n’ with repetition of factors if exist.

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.factors(``774177``) ` `print``(a) ` ` `  `a ``=` `primes.factors(``15``) ` `print``(a) `

Output:

```[3, 151, 1709]
[3, 5]
```
• primes.first(n) : It will return first ‘n’ prime numbers .

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.first(``5``) ` `print``(a) ` ` `  `a ``=` `primes.first(``10``) ` `print``(a) `

Output:

```[2, 3, 5, 7, 11]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
```
• primes.upto(n) : It will return all the prime numbers less than or equal to ‘n’.

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.upto(``17``) ` `print``(a) ` ` `  `a ``=` `primes.upto(``100``) ` `print``(a) `

Output:

[2, 3, 5, 7, 11, 13, 17]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

• primes.between(m, n): It will return all the prime numbers between m and n .

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.between(``4``, ``15``) ` `print``(a) ` ` `  `a ``=` `primes.between(``25``, ``75``) ` `print``(a) `

Output:

```[5, 7, 11, 13]
[29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73]
```

7. primes.phi(n) : It will return the number of integers less than ‘n’ which have no common factor with n.

Example:

 `# Importing primes function  ` `# From primePy Library  ` `from` `primePy ``import` `primes ` ` `  ` `  `a ``=` `primes.phi(``5``) ` `print``(a) ` ` `  `a ``=` `primes.phi(``10``) ` `print``(a) `

Output:

```4
4
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.