mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(challenges): add prime-numbers-decomposition
This commit is contained in:
parent
0a27b9e1a1
commit
74ded41d4d
36
challenges/prime-numbers-decomposition/README.md
Normal file
36
challenges/prime-numbers-decomposition/README.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# prime-numbers-decomposition
|
||||||
|
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) on 16 October 2021.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
## Definition
|
||||||
|
|
||||||
|
In mathematics, product decomposition of prime factors (also known as integer factorization into prime numbers) involves writing a strictly positive integer as a product of prime numbers.
|
||||||
|
|
||||||
|
This factorization is unique and exists for all numbers and has many applications, particularly in RSA cryptography.
|
||||||
|
|
||||||
|
**Note :** A prime number is a natural integer which admits exactly two distinct positive divisors. (1 and itself). Example: 2, 3, 5, 7, 11, 13, 17, 19...
|
||||||
|
|
||||||
|
## How to decompose a number into a product of factors of prime numbers?
|
||||||
|
|
||||||
|
To find the product decomposition of prime factors of a number `N`, there is no mathematical formula. To achieve this, there are algorithms, the most basic of which attempts to divide the number `N` by the set of prime factors `p` which are less than `N`.
|
||||||
|
If `p` is a divisor of `N` then start again by taking a new `N = N / p` as long as there are possible prime divisors.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
```txt
|
||||||
|
32
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
```txt
|
||||||
|
2 * 2 * 2 * 2 * 2
|
||||||
|
```
|
||||||
|
|
||||||
|
See the `test` folder for examples of input/output.
|
1
challenges/prime-numbers-decomposition/test/1/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/1/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
4
|
1
challenges/prime-numbers-decomposition/test/1/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/1/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
2 * 2
|
1
challenges/prime-numbers-decomposition/test/2/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/2/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
151
|
1
challenges/prime-numbers-decomposition/test/2/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/2/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
151
|
1
challenges/prime-numbers-decomposition/test/3/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/3/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
32
|
1
challenges/prime-numbers-decomposition/test/3/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/3/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
2 * 2 * 2 * 2 * 2
|
1
challenges/prime-numbers-decomposition/test/4/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/4/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1358280
|
1
challenges/prime-numbers-decomposition/test/4/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/4/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
2 * 2 * 2 * 3 * 3 * 5 * 7 * 7 * 7 * 11
|
1
challenges/prime-numbers-decomposition/test/5/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/5/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1433250
|
1
challenges/prime-numbers-decomposition/test/5/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/5/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
2 * 3 * 3 * 5 * 5 * 5 * 7 * 7 * 13
|
1
challenges/prime-numbers-decomposition/test/6/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/6/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
31861
|
1
challenges/prime-numbers-decomposition/test/6/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/6/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
151 * 211
|
1
challenges/prime-numbers-decomposition/test/7/input.txt
Normal file
1
challenges/prime-numbers-decomposition/test/7/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
31243
|
1
challenges/prime-numbers-decomposition/test/7/output.txt
Normal file
1
challenges/prime-numbers-decomposition/test/7/output.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
157 * 199
|
Loading…
Reference in New Issue
Block a user