generate functionSun, 05 Mar 2023

1. define f(a, b, c, m, i) = Floor[(a*i^2+b*i+c)/m]. 2. define a function T to find S = Sum[f(a, b, c, m, i), {i, 1, n}]. 3. define the values of a, b, c, and m randomly as positive integers less than or equal to 10. 4. if the running time of T exceeds log(n) for a function T with natural number n when n=10^j with j=1, derive an algorithm whose running time does not exceed log(n) for n=10^j, and define a new efficient recursive function U that optimizes the function T using this algorithm. 5. compute and output S using U.

import random import math def f(a, b, c, m, i): return math.floor((a*i*i + b*i + c)/m) def T(n): a = random.randint(0, 10) b = random.randint(0, 10) c = random.randint(0, 10) m = random.randint(0, 10) s = 0 for i in range(n): s += f(a, b, c, m, i) return s def U(n): if n <= 10: return T(n) else: s = 0 s += U(math.floor(n/2)) s += U(math.ceil(n/2)) return s print(U(10**1))

Questions about programming?Chat with your personal AI assistant