Skip to content

Instantly share code, notes, and snippets.

@mutoo
Last active December 17, 2015 19:29
Show Gist options
  • Select an option

  • Save mutoo/5660641 to your computer and use it in GitHub Desktop.

Select an option

Save mutoo/5660641 to your computer and use it in GitHub Desktop.
整数分解 via miloyip(http://weibo.com/1747724431/yc8lfoCmJ)
function f(s, n, i) {
if (n == 0) return s + "<br/>";
else {
var p = (s == "") ? n + "=" : s + "+";
var m = (s == "") ? n - 1 : n;
var r = "";
for (var j = i; j <= m; j++)
r += f(p + j, n - j, j);
return r;
}
}
function g(n) {
return f("", n, 1);
}
document.write(g(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment