Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mmc {
- #private $primos = array(2, 3, 5, 7);
- public $mmc;
- private $checar = 2;
- public function __construct($numeros){
- $retMMC = 1;
- foreach(array_unique($numeros) as $numero){
- $numero = $this->fatorarPrimo($numero);
- $retMMC = $retMMC * array_product(array_unique($numero));
- }
- return $restMMC;
- }
- public function fatorarPrimo($numero){
- $checar = $this->checar;
- $primos = array();
- while(($checar * $checar) <= $numero){
- if(($numero % $checar) == 0){
- $numero = $numero/$checar;
- $primos[] = $checar;
- }
- else {
- $checar++;
- }
- }
- if($numero != 1){
- $primos[] = $numero;
- }
- return $primos;
- }
- }
- $dae = new mmc(array(15, 20));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement