Highest perimeter polyomino
Ruby, Rev 1, 66
-&gt;(m,n){n.times{|i|puts (&quot;#&quot;*m**(1-i%2)).rjust(m,i&gt;n-2?&quot;# &quot;:&quot; &quot;)}}

Used raising m to power 0 o 1 to decide whether 1 or m #'s will be printed.
Used &gt; to test for last row instead of ==.
Can't get rid of the space after puts, nor any brackets!
Ruby, Rev 0, 69
-&gt;(m,n){n.times{|i|puts (&quot;#&quot;*(i%2==0?m:1)).rjust(m,i==n-1?&quot;# &quot;:&quot; &quot;)}}

This is an anonymous lambda function. Use it like this:
f=-&gt;(m,n){n.times{|i|puts (&quot;#&quot;*(i%2==0?m:1)).rjust(m,i==n-1?&quot;# &quot;:&quot; &quot;)}}

M=gets.to_i
N=gets.to_i
f.call(M,N)

In the end, after asking if M and N could be interchanged I didnt need it.

Typical outputs for N odd. If we delete the # on their own on the right hand side, clearly we will have (N+1)(M+1). Including them to join the shape removes 2 squares of horizontal perimeter and adds 2 squares of vertical perimeter, so there is no change.
Here we rely on the expression &quot;#&quot;*(i%2==0?m:1) to give alternating rows of M# symbols and one # symbol, and right justify to M characters.
5                        6
5                        5
#####                    ######
    #                         #
#####                    ######
    #                         #
#####                    ######


Typical outputs for N even. 5 6 clearly has the same perimeter as 6 5, or an increment of M+1=6 compared with 5 5 by addition of vertical perimeter due to the crenelation of the bottom row. 6 6 has the same as 6 5 plus an increment of (M+1)-1=6 in the vertical perimeter. Thus they are in accordance with the formula.
5                        6
6                        6
#####                    ######
    #                         #
#####                    ######
    #                         #
#####                    ######
# # #                    # # ##

It's very handy that Ruby's rjust allows you to specify the padding to use for the empty cells. Normally the padding is set to &quot; &quot; but for the last row we switch to &quot;# &quot; (note that padding will only be needed on the last row if N is even. Where N is odd the last row will be complete and there will be no justifying, so you won't see the crenelations.)
Check it out here.