Question: You are given an array A of length N . A subsequence is said to be great if the GCD of the elements of the
You are given an array A of length N A subsequence is said to be great if the GCD of the elements of the subsequence is greater than An empty subsequence is not a great subsequence. You are given Q queries and in each query you are given two integers X and Y x N Y You need to replace the Xth element in A with Y In other words, set AX Y Let the answer to each query be the number of great subsequences. Let's define an array S containing the answer to each query. Find the sum of S Since the answer can be large, return it modulo Input Format The first line contains an integer, N denoting the number of elements in A Each line i of the N subsequent lines where sisN contains an integer describing A The next line contains an integer, Q denoting the number of rows in queries. The next line contains an integer, P denoting the number of columns in queries.Each line i of the Q subsequent lines where i Q contains P space separated integers each describing the row queriesiConstraints N Ai Q P queriesij Import sysdef get Subsequencel ount N A Q P queries:write your code hereMintsysstdin.readlinestripAfor in rangeN:Aappendintsysstdin.readlinestripQintsysstdin.readlinestripPintsysstdin.readlinestripqueries Ifor in rangeQ:queries.appendlistmaplambda x: intx sysstdin.readl
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
