Language: C++

var fs, max, scale, max_log2, max_pow2, series;

fs = require('fs');

max = 300;

function log2(n) {
	return n.toString(2).length - 1;
}

max_log2 = Math.floor(log2(max));
max_pow2 = Math.pow(2, max_log2);

series = function(max_pow2) {
	var i, series = [];
	for (i = max_pow2; i >= 1; i /= 2) series.push(i);
	return series;
} (max_pow2);

scale = function(max) {
	var scale, i, str;
	scale = [];
	str = "#";
	for (i = 1; i < max; i *= 2) {
		scale.push(str);
		str = str + str;
	}
	return scale.reverse();
}(max);

function get_column(W) {
	var i, res, rest;
	res = "";
	rest = W;
	for (i in series) {
		if (rest >= series[i]) {
			rest -= series[i];
			res = res + scale[i];
		}
	}
	return res;
}

function repeat(str, n) {
	return get_column(n).replace(/#/g, str);
}

function main() {
	var line, i, hw, end_i;
	line = fs.readFileSync('/dev/stdin', 'ascii').split("\n");
	end = false;
	for (i in line) {
		hw = line[i].split(' ', 2).map(Number);
		if (hw[0] === 0 && hw[1] === 0) {
			end_i = Number(i);
			break;
		}
		line[i] = repeat(get_column(hw[1]) + "\n", hw[0]) + "\n";
	}
	line.length = end_i;
	console.log(line.join("").trim() + "\n");
}

main();

Compiler output:
a.cc:3:14: warning: multi-character character constant [-Wmultichar]
    3 | fs = require('fs');
      |              ^~~~
a.cc:45:39: error: stray '#' in program
   45 |         return get_column(n).replace(/#/g, str);
      |                                       ^
a.cc:50:32: warning: multi-character literal with 10 characters exceeds 'int' size of 4 bytes
   50 |         line = fs.readFileSync('/dev/stdin', 'ascii').split("\n");
      |                                ^~~~~~~~~~~~
a.cc:50:46: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   50 |         line = fs.readFileSync('/dev/stdin', 'ascii').split("\n");
      |                                              ^~~~~~~
a.cc:1:1: error: 'var' does not name a type
    1 | var fs, max, scale, max_log2, max_pow2, series;
      | ^~~
a.cc:3:1: error: 'fs' does not name a type
    3 | fs = require('fs');
      | ^~
a.cc:5:1: error: 'max' does not name a type
    5 | max = 300;
      | ^~~
a.cc:7:1: error: 'function' does not name a type; did you mean 'union'?
    7 | function log2(n) {
      | ^~~~~~~~
      | union
a.cc:11:1: error: 'max_log2' does not name a type
   11 | max_log2 = Math.floor(log2(max));
      | ^~~~~~~~
a.cc:12:1: error: 'max_pow2' does not name a type
   12 | max_pow2 = Math.pow(2, max_log2);
      | ^~~~~~~~
a.cc:14:1: error: 'series' does not name a type
   14 | series = function(max_pow2) {
      | ^~~~~~
a.cc:18:13: error: expected constructor, destructor, or type conversion before ';' token
   18 | } (max_pow2);
      |             ^
a.cc:20:1: error: 'scale' does not name a type
   20 | scale = function(max) {
      | ^~~~~
a.cc:29:7: error: expected constructor, destructor, or type conversion before ';' token
   29 | }(max);
      |       ^
a.cc:31:1: error: 'function' does not name a type; did you mean 'union'?
   31 | function get_column(W) {
      | ^~~~~~~~
      | union
a.cc:44:1: error: 'function' does not name a type; did you mean 'union'?
   44 | function repeat(str, n) {
      | ^~~~~~~~
      | union
a.cc:48:1: error: 'function' does not name a type; did you mean 'union'?
   48 | function main() {
      | ^~~~~~~~
      | union
a.cc:64:7: error: expected constructor, destructor, or type conversion before ';' token
   64 | main();
      |       ^