<div id="output"></div>
.mark {
  background: lime;
}
View Compiled
// utilies para escribir
$output = $('#output');

function write(s, htmlClass) {
  var htmlClass = (htmlClass == undefined)?'':htmlClass;
  s = (s == undefined)?'':s;
  $('<span class="' + htmlClass + '">' + s + '</span>').appendTo($output);
}

function writeln(s, htmlClass) {
  var htmlClass = (htmlClass == undefined)?'':htmlClass;
  s = (s == undefined)?'':s;
  $('<div class="' + htmlClass + '">' + s + '</div>').appendTo($output);
}

// contando desde 1
for (var n=1; n<300; n++) {
  // escribiendo divisores de n
  write(n + ': ');
  var s = 0;
  if (n == 1) {
      write(1 + ' ');
      s += 1;
  }
  for (var d=1; 2*d<=n; d++) {
    if (n%d == 0) {
      write(d + ' ');
      s += d;
    }
  }
  write('-> ' + s);
  
  // escribiendo divisores de s
  write(': ');
  var ss = 0;
  if (s == 1) {
      write(1 + ' ');
      ss += 1;
  }
  for (var d=0; 2*d<=s; d++) {
    if (s%d == 0) {
      write(d + ' ');
      ss += d;
    }
  }
  write('-> ' + ss);  
  if (ss == n) {
    write('OK', 'mark');  
  }
  writeln();
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js