Magic triangles P32090


Statement
 

pdf   zip

We define a magic triangle of size nn as a triangle with nn rows, the first one with nn elements, the second one with n1n - 1 elements, …, and the last one with one element, such that:

  • All numbers between 1 and n(n+1)/2n(n + 1)/2 appear once.

  • Each number that is not in the first row is equal to the absolute value of the difference of the two values immediately above it.

Write a program that, given an nn, prints all the magic triangles of size nn, or indicates that there is none.

Input

Input consists of a natural number n>0n > 0.

Output

Print all the magic triangles of size nn. Note that the numbers are always written with two digits (if needed, adding a zero to the left), and that they are separated with two spaces. Print an empty line after each triangle.

Ignore the triangles that are symmetrical of any other lexicographically smaller. If there is no possible triangle for the given nn, indicate it following the format of the example.

Observation

It can be proved that there is no solution for n6n \ge 6, but do not use this fact in your program.

Information about the checker

You can print the solutions to this exercise in any order.

Public test cases
  • Input

    2
    

    Output

    01  03
      02
    
    02  03
      01
    
    
  • Input

    5
    

    Output

    06  14  15  03  13
      08  01  12  10
        07  11  02
          04  09
            05
    
    
  • Input

    6
    

    Output

    no solution for n = 6
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions