Sequence GCD WGCD Solution Codechef
Codechef Sequence GCD WGCD Solution You are given an integer sequence A=(A1,A2,…,AN) of length N and an integer M such that 0≤M<∑i=1NAi. An integer sequence B=(B1,B2,…,BN) of length N is called good if: Find the maximum value of gcd(A1−B1,A2−B2,…,AN−BN) over all good sequences B. Here, gcd denotes the greatest common divisor. Note: gcd(a,b,c)=gcd(a,gcd(b,c)) and gcd(a,0)=gcd(0,a)=a. Input Format Output Format For each test case, print a single line containing one integer — the maximum value of gcd(A1−B1,A2−B2,…,AN−BN) over all good sequences B. Constraints Subtasks Subtask #1 … Read more