function [valid, perNode, nodes] = getNodePerNode(p, maxNodes, maxPerNode)

valid = false;
perNode = -1;
nodes = -1;

for pn = maxPerNode:-1:1
  if ( mod(p,pn) == 0 && p/pn <= maxNodes )
    valid = true;
    perNode = pn;
    nodes = p/pn;
    return;
  end
end

end
