<?php
function divide($lo, $hi, &$m) {
$m = ($lo + $hi) >> 1;
}
function combo($a, $b, &$c) {
$c = $a + $b;
}
function divideEtImpera($arr, $lo, $hi, &$z) {
if($lo == $hi) {
$z = $arr[ $lo ];
} else {
divide($lo, $hi, $m);
divideEtImpera($arr, $lo, $m, $a);
divideEtImpera($arr, $m + 1, $hi, $b);
combo($a,$b,$z);
}
}
$arr = array(1,2,3,4,5,6,7,8,9,10);
divideEtImpera
($arr, 0, sizeof($arr) - 1, $z);echo"Sum 1 + 2 + 3 + ...+ 10 = ". $z;
?>
PD9waHAKCmZ1bmN0aW9uIGRpdmlkZSgkbG8sICRoaSwgJiRtKSB7CgogICAgICAgJG0gPSAoJGxvICsgJGhpKSA+PiAxOwp9CgpmdW5jdGlvbiBjb21ibygkYSwgJGIsICYkYykgewoKICAgJGMgPSAkYSArICRiOwp9CgpmdW5jdGlvbiBkaXZpZGVFdEltcGVyYSgkYXJyLCAkbG8sICRoaSwgJiR6KSB7CgogICAgICAgICBpZigkbG8gPT0gJGhpKSB7CgogICAgICAgICAgICAgICR6ID0gJGFyclsgJGxvIF07CgogICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGRpdmlkZSgkbG8sICRoaSwgJG0pOwogICAgICAgICAgICAgIGRpdmlkZUV0SW1wZXJhKCRhcnIsICRsbywgJG0sICRhKTsKICAgICAgICAgICAgICBkaXZpZGVFdEltcGVyYSgkYXJyLCAkbSArIDEsICRoaSwgJGIpOwogICAgICAgICAgICAgIGNvbWJvKCRhLCRiLCR6KTsKICAgICAgICAgfQp9CgokYXJyID0gYXJyYXkoMSwyLDMsNCw1LDYsNyw4LDksMTApOwoKZGl2aWRlRXRJbXBlcmEoJGFyciwgMCwgc2l6ZW9mKCRhcnIpIC0gMSwgJHopOwplY2hvIlN1bSAxICsgMiArIDMgKyAuLi4rIDEwID0gIi4gJHo7Cj8+Cg==