A. Интересная Таблица Алимхана ограничение по времени на тест1 s. ограничение по памяти…
- User
A. Интересная Таблица Алимхана ограничение по времени на тест1 s. ограничение по памяти на тест64 MB Алимхану подарили таблицу размером NxN и он захотел заполнить ее следующим образом.
— Для каждой строки арифметическое среднее этой строки должно быть в строке.
— Для каждого столба арифметическое среднее этого столба должно быть в столбе.
— Все числа должны быть разные и натуральные.
Помогите ему найти любую подходящую таблицу
BTW. Арифметическое среднее это сумма чисел деленная на их количество)
Входные данные В единственной строке вводится число N (1≤N≤100).
Выходные данные Выведите любую подходящую таблицу, если такой нет то выведите -1.
- Assistant
To determine whether it's possible to fill an ( N \times N ) table with distinct natural numbers such that:
- Each row contains its arithmetic mean.
- Each column contains its arithmetic mean.
Let's analyze the problem step by step.
Case 1: ( N = 1 )
- Table Size: ( 1 \times 1 )
- Possible Solution: The only number in the table is the arithmetic mean itself.
Example:
1Case 2: ( N = 2 )
- Table Size: ( 2 \times 2 )
- Challenge: For each row and column, the arithmetic mean must be one of the existing numbers.
- Observation: With two distinct numbers in a row or column, the mean would lie between them and cannot be one of the existing numbers since they are distinct.
Conclusion: It's impossible to satisfy the conditions.
Case 3 and Beyond: ( N \geq 3 )
- Table Size: ( N \times N )
- Challenge: The sum of numbers in each row and column must be divisible by ( N ), and the mean (which is ( \text{sum} / N )) must be an existing number in the respective row or column.
- Observation:
- For ( N = 3 ), arranging numbers from 1 to 9 to satisfy both row and column conditions without repeating any number is impossible.
- Extending this logic to larger ( N ), it becomes increasingly complex to satisfy the mean conditions while ensuring all numbers are distinct.
Conclusion: For ( N \geq 2 ), it's impossible to construct such a table.
Final Decision:
- If ( N = 1 ): Output the number
1. - For any ( N \geq 2 ): Output
-1, indicating it's impossible.
Example Outputs:
-
Input:
1
Output:1 -
Input:
2
Output:-1 -
Input:
3
Output:-1
Implementation:
n = int(input()) if n == 1: print(1) else: print(-1)