The basic methodology is to use a sieve to maintain an increasing list of prime numbers, and to work through those numbers until the remainder is 1. In the event that no factors are found up till the square root of the number, it is presumed that any remaining value is prime.

Execution time (Core i5, 4GB RAM, Windows/Apache (not-optimized)) is:

~35ms for n ~10^{9}

~3.5ms for n ~10^{7}

~0.6ms for n ~10^{5}

If looping through many numbers (instead of finding a single solution), maintaining the sieve array will greatly increase efficiency.

```
function pfactor($n){
// max_n = 2^31-1 = 2147483647
$d=2;
$factors = array();
$dmax = floor(sqrt($n));
$sieve = array();
$sieve = array_fill(1, $dmax,1);
do{
$r = false;
while ($n%$d==0){
$factors[$d]++;
$n/=$d;
$r = true;
}
if ($r){
$dmax = floor(sqrt($n));
}
if ($n>1){
for ($i=$d;$i<=$dmax;$i+=$d){
$sieve[$i]=0;
}
do{
$d++;
}while ($sieve[$d]!=1 && $d<$dmax);
if ($d>$dmax){
$factors[$n]++;
}
}
}while($n>1 && $d<=$dmax);
return $factors;
}
```

Usage is quite simple - just pass a number, the return is value is an array, with keys being the prime factors, and values being the exponents:

```
$x=12345;
$factors = pfactor($x);
$fstr = "";
foreach ($factors as $b=>$e){
if($fstr){$fstr .= " x ";}
$fstr .= "$b" . ($e>1?"
```^{$e}":"");
}

]]>While by no means a perfect class (quite possibly a rather poorly coded class), the following provides some basic functions necessary for working with fractions.

```
n = $num;
$this->d = $den;
}
public function gcf($n1, $n2){
if ($n2>$n1){
$tmp = $n1;
$n1=$n2;
$n2=$tmp;
}
do{
$rem = $n1 % $n2;
$n1 = $n2;
$n2 = $rem;
}while($rem!=0);
return $n1;
}
public function lcm($n1, $n2){
return $n1*($n2/frac::gcf($n1,$n2));
}
public function reduce (){
$g = $this->gcf($this->n,$this->d);
$this->n /= $g;
$this->d /= $g;
}
public function multiply (frac $n1, frac $n2){
$f = new frac($n1->n*$n2->n,$n1->d*$n2->d);
$f->reduce();
return $f;
}
public function divide (frac $n1, frac $n2){
return frac::multiply($n1, new frac($n2->d,$n2->n));
}
public function add (frac $n1, frac $n2){
$g = frac::lcm($n1->d,$n2->d);
$f= new frac($n1->n*($g/$n1->d)+$n2->n*($g/$n2->d),$g);
$f->reduce();
return $f;
}
public function subtract (frac $n1, frac $n2){
return frac::add($n1, new frac(-1*$n2->n,$n2->d));
}
public function display(){
return $this->n . "/" . $this->d;
}
}
?>
```

Examples of use:

1/3 + 1/2:

```
display();
?>
```

1/8 * 2/5

```
display();
?>
```

The `gcf`

function uses Euclid’s algorithm, and the `lcm`

function (used to find the common denominator) calls the `gcf`

function.

Given the significant disparity between the ease with which a computer can ‘learn’ fractions, and the difficulty encountered by most students, perhaps it is time to consider teaching fractions as a series of concrete steps – an algorithm – instead of the current method. (Granted, most current methods do provide a method for arriving at an answer, but especially for the determination of the lowest common denominator (or reducing fractions), a procedural methodology (e.g. prime factoring, Euclid’s method, etc) is rarely given.)

]]>A traditional display has a ratio (width:length) of 4:3, screen size is typically given as the diagonal (or if we are thinking triangles, the hypotenuse).

Let:

d represent the diagonal

w represent the width

h represent the height

A represent the area

We get two equations:

Using the Pythagorean theorem:

1:

Using the ratio of length to width:

2:

Equation 3, comes from substituting 2 into 1, we get:

Equation 4 comes from substituting 3 into 2 we get w, which we will use to find area:

Therefore, the area of the 4:3 display (equation 5) is:

Following the same procedure for the 16:9 display, we get:

2:

3:

4:

5:

The ratio of the area of the 4:3 display to the 16:9 display, therefore, is:

In other words, you get about 12% extra screen area on a traditional, 4:3 display, compared to a widescreen 16:9 display. Not exactly a revelation perhaps, not something that immediately springs to mind. The advantage (of the widescreen), perhaps comes in the form of usable area for an image displayed in widescreen, where the 4:3 display will likely have less usable area.

]]>