Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.     class mmc {
  3.         #private $primos = array(2, 3, 5, 7);
  4.         public $mmc;
  5.         private $checar = 2;
  6.  
  7.         public function __construct($numeros){
  8.             $retMMC = 1;
  9.             foreach(array_unique($numeros) as $numero){
  10.                 $numero = $this->fatorarPrimo($numero);
  11.                 $retMMC = $retMMC * array_product(array_unique($numero));
  12.             }
  13.             return $restMMC;
  14.         }
  15.  
  16.         public function fatorarPrimo($numero){
  17.             $checar = $this->checar;
  18.             $primos = array();
  19.             while(($checar * $checar) <= $numero){
  20.                 if(($numero % $checar) == 0){
  21.                     $numero = $numero/$checar;
  22.                     $primos[] = $checar;
  23.                 }  
  24.                 else {
  25.                     $checar++;
  26.                 }
  27.             }
  28.            
  29.             if($numero != 1){
  30.                 $primos[] = $numero;
  31.             }
  32.  
  33.             return $primos;
  34.         }  
  35.     }
  36.  
  37.     $dae = new mmc(array(15, 20));
  38.    
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement