Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please finish the code by adding under (##add code here) in python, the two photos are the instructions and the time limit for running the
please finish the code by adding under (##add code here) in python, the two photos are the instructions and the time limit for running the code is 1000ms. it is not allowed to import fraction. Thank you!
code:
def solution(X, Y): ##add code here
return c
if __name__ == "__main__": X = [ int(value) for value in input().split(",") if len(value) > 0 ] Y = [ int(value) for value in input().split(",") if len(value) > 0 ] print(solution(X,Y))
instructions:
Sum To1 Description You are given N fractions. Fractions are represented as two arrays, X and Y of length N, containing the fraction numerators and denominators respectively. Write a functionsolutionthat, given such arrays X and Y of length N, returns the number of possible ways to choose a pair of fra ctions that sum up to 1. Since the answer can be large, provide it modulo 109+ 7 (1,000,000,007). Note that a single fraction ca n form multiple pairs. Examples: 1. Given X = [1, 1, 2], Y = [3, 2, 3], the function should return 1. The input represents fractions1/3,1/2,2/3, and the only pair that sums up to 1 is (1/3,2/3). 2. Given X = [1, 1, 1], Y = [2, 2, 2], the function should return 3. The input represents 1/2,1/2,1/2. There are three ways to choose a pair that sums up to 1. 3. Given X = [1, 2, 3, 1, 2, 12, 8, 4], Y = [5, 10, 15, 2, 4, 15, 10, 5], the function should return 10. Write anefficientalgorithm for the following assumptions: N is an integer within the range [0..100,000); each element of arrays X, Y is an integer within the range [1..1,000,000,000]. Input Input Two list of integers. First list represents numerators, and second list represents denominators. Output The number of possible ways to choose a pair of fractions that sum up to 1. Sample Input 1 ] Sample Output 1 1 1,1,2 3,2,3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started