Binary Matrix
Time limit0.5sMemory limit512 MB
Given an n by n binary matrix K, find the smallest k such that K^k equals K^m for some earlier m, computing entries mod 2.
- Level
Medium5 of 10
- Topics
- Matrix, Math, Simulation
- Solved
- No attempts yet
Problem
Kipa received an n by n table filled with 0 and 1 as a gift from Yul. Kipa treats the table as a matrix and names it . Kipa likes that every entry of is either 0 or 1, so Kipa decides to write 0 for an even value and 1 for an odd value in every entry of each computed result.
Kipa first tried adding, computing , , and , but soon lost interest because is all zeros. So Kipa turned to multiplication. While computing , , , and so on, Kipa noticed the same computation seemed to repeat.
Kipa thinks a computer should do repetitive work, so Kipa wants to know when the multiplication becomes boring. Write a program that prints how many times appears in the product expression when Kipa sees a previous result again.
Input
The first line contains the size of the matrix.
The next lines contain numbers in total, separated by spaces. Every number is either 0 or 1.
Output
Print the number of times appears in the product expression when Kipa sees a previous result again.
Hint
Stated mathematically, given a matrix , print the smallest element of the subset of natural numbers