Skip to content

Instantly share code, notes, and snippets.

View Francis-Njoku's full-sized avatar

Francis Xavier Francis-Njoku

View GitHub Profile
@Francis-Njoku
Francis-Njoku / Fibonacci.php
Created January 6, 2020 04:48
Fibonacci sequence with index of first term to contain 1000 digits
<?php
// Function to generate fibonacci sequence that contains large numbers
function getFibonacci() {
$i = '0';
$k = '1'; //first fibonacci value
yield $k;
while(true) {
// gmp_add to add two gmp number (www.php.net/manual/en/ref.gmp.php)
$k = gmp_add($i, $k);
// gmp_subtract to subtract $i from $k
@Francis-Njoku
Francis-Njoku / Find_highest_prime_factor.php
Created January 6, 2020 04:46
Find the largest prime factor of the number 600851475143
<?php
function find_highest_prime_factor($n)
{
for ($i = 2; $i <= $n; $i++)
{
if (bcmod($n, $i) == 0) //its a factor
{
return max($i, $this->find_highest_prime_factor(bcdiv($n,$i)));
}
}
@Francis-Njoku
Francis-Njoku / Fibonacci.php
Created January 6, 2020 04:40
Fibonacci sequence with index of first term to contain 1000 digits
<?php
// Function to generate fibonacci sequence that contains large numbers
function getFibonacci() {
$i = '0';
$k = '1'; //first fibonacci value
yield $k;
while(true) {
// gmp_add to add two gmp number (www.php.net/manual/en/ref.gmp.php)
$k = gmp_add($i, $k);
// gmp_subtract to subtract $i from $k