@@ -149,40 +149,47 @@ This class treats basic matters of primes.
149149 // judge if all of $n are prime or not
150150 $n = [ 2, 3, 5, ];
151151 echo sprintf(
152- "Are all of [%s] prime? - %s.\n",
152+ "Are all of [%s] prime? - %s.\n\n ",
153153 implode(', ', $n),
154154 $p->isPrimeAll($n) ? 'Yes' : 'No'
155155 );
156156
157+ // a prime previous to $n
158+ $n = 5;
159+ echo sprintf("A prime previous to %d is %d.\n", $n, $p->previous($n));
160+
157161 // a prime next to $n
158162 $n = 5;
159- echo sprintf("A prime next to %d is %d.\n", $n, $p->next($n));
163+ echo sprintf("A prime next to %d is %d.\n\n ", $n, $p->next($n));
160164
161165 // primes between $a and $b
162166 $a = 6;
163167 $b = 14;
164168 echo sprintf(
165- "Primes between %d and %d are [%s].\n",
169+ "Primes between %d and %d are [%s].\n\n ",
166170 $a,
167171 $b,
168172 implode(', ', $p->between($a, $b))
169173 );
170174
171175 // factorize
172176 $n = 1234567890;
173- echo sprintf("Factorize %d:\n", $n);
177+ echo sprintf("Factorize %d:\n\n", $n);
178+
174179 $r = $p->factorize($n);
175180 $l1 = $p->numberOfDigits(max(array_column($r, 0)));
176181 $l2 = $p->numberOfDigits(max(array_column($r, 1)));
177182 $s = str_repeat(' ', $l1 + 1);
178183 $b = $s . str_repeat('-', $l2);
184+
179185 foreach ($r as $f) {
180186 echo (
181187 $f[0]
182188 ? sprintf("%" . $l1 . "d)%" . $l2 . "d\n%s\n", $f[0], $f[1], $b)
183189 : sprintf("%s%" . $l2 . "d\n", $s, $f[1])
184190 );
185191 }
192+ echo "\n";
186193
187194 // Factorized formula
188195 echo $n . " = " . $p->factorizedFormula($n)['formula'] . "\n";
@@ -193,9 +200,14 @@ This class treats basic matters of primes.
193200 ```
194201 Is 3 prime? - Yes.
195202 Are all of [2, 3, 5] prime? - Yes.
203+
204+ A prime previous to 5 is 3.
196205 A prime next to 5 is 7.
206+
197207 Primes between 6 and 14 are [7, 11, 13].
208+
198209 Factorize 1234567890:
210+
199211 2)1234567890
200212 ----------
201213 3) 617283945
@@ -207,6 +219,7 @@ This class treats basic matters of primes.
207219 3607) 13717421
208220 ----------
209221 3803
222+
210223 1234567890 = 2 * 3 ^ 2 * 5 * 3607 * 3803
211224 ```
212225
@@ -216,6 +229,7 @@ This class treats basic matters of primes.
216229 | :---| :---|
217230 | ` isPrime(int $n) ` | judges if the param is prime or not|
218231 | ` isPrimeAll(array $elements) ` | judges if all of the param are prime or not|
232+ | ` previous(int $n) ` | returns a prime previous to the param|
219233 | ` next(int $n) ` | returns a prime next to the param|
220234 | ` between(int $a, int $b) ` | returns array of primes between the params|
221235 | ` factorize(int $n) ` | factorize the param and returns the process as an array|
@@ -593,6 +607,6 @@ This class treats basic matters of Bezout's Identity.
593607
594608* Document Created: 2023/10/19*
595609
596- * Document Updated: 2024/03/16 *
610+ * Document Updated: 2024/04/17 *
597611
598612Copyright 2023 - 2024 macocci7
0 commit comments