1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! # Numbers
//! This module contains functions related to numbers.
//! The functions include finding prime numbers, checking if a number is prime, finding factorial, gcd, lcm etc in Rust.
//! # Examples
//! ```
//! use rusty_math::numbers;
//! let result = numbers::gcd(12, 15);
//! ```
/// Function to find all the prime numbers less than a given number
/// Uses the Sieve of Eratosthenes algorithm
/// # Paramaters:
/// num: `usize` - The positive number upto which the prime numbers are to be found
/// # Returns:
/// `Vec<usize>` - A vector containing all the prime numbers less than the given number
/// # Examples
/// ```
/// use rusty_math::numbers::primes;
/// let result = primes(10);
/// ```
/// Function to check if a number is prime
/// # Paramaters:
/// num: `usize` - The positive number to be checked
/// # Returns:
/// `bool` - True if the number is prime, False otherwise
/// # Examples
/// ```
/// use rusty_math::numbers::isprime;
/// let result = isprime(7);
/// ```
/// Function to find the factorial of a number
/// # Paramaters:
/// num: `usize` - The positive number whose factorial is to be found
/// # Returns:
/// `usize` - The factorial of the given number
/// # Examples
/// ```
/// use rusty_math::numbers::factorial;
/// let result = factorial(5);
/// ```
/// Panics if the input is negative
/// Function to find the greatest common divisor of two numbers
/// # Paramaters:
/// a: `i32` - The first number
/// b: `i32` - The second number
/// # Returns:
/// `i32` - The greatest common divisor of the two numbers
/// # Panics:
/// If the input is negative
/// # Examples
/// ```
/// use rusty_math::numbers::gcd;
/// let result = gcd(12, 15);
/// ```
/// Panics if the input is negative
/// Function to find the least common multiple of two numbers
/// # Paramaters:
/// a: `i32` - The first number
/// b: `i32` - The second number
/// # Returns:
/// `i32` - The least common multiple of the two numbers
/// # Panics:
/// If the input is negative
/// # Examples
/// ```
/// use rusty_math::numbers::lcm;
/// let result = lcm(12, 15);
/// ```
/// Panics if the input is negative