#3725
Count Ways to Choose Coprime Integers from Rows
hard · 48.3% accepted · 63 likes · top 34%
array · math · dynamic programming · matrix · combinatorics · number theory
Description
You are given a m x n matrix mat of positive integers.
Return an integer denoting the number of ways to choose exactly one integer from each row of mat such that the greatest common divisor of all chosen integers is 1.
Since the answer may be very large, return it modulo 109 + 7.
Solution