local n, k = io.read("*n") local edge = {} local deg = {} for i = 1, n do deg[i] = 0 edge[i] = {} end deg[1], deg[2] = 1, 1 edge[1][1] = 2 for i = 2, n do local rem = i - deg[i] for j = i + 1, n do if deg[j] < j then table.insert(edge[i], j) deg[i] = deg[i] + 1 deg[j] = deg[j] + 1 rem = rem - 1 end if rem == 0 then break end end end local m = 0 for i = 1, n do m = m + #edge[i] end print(m) for i = 1, n do for j = 1, #edge[i] do print(i .. " " .. edge[i][j]) end end