Generation

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. for n=10^j with j=1, if the running time of T exceeds log(n) for function T with natural number n, derive an algorithm whose running time does not exceed log(n) for n=10^j, and define a new function U that optimizes function T using this algorithm. 5. compute and output S using U.

def f(a,b,c,m,i): return (a*i**2+b*i+c)/m def T(n,a,b,c,m): S = 0 for i in range(1,n+1): S += f(a,b,c,m,i) return S a, b, c, m = np.random.randint(1,11,4) n = 10 print(n) print('{0} * i^2 + {1} * i + {2} / {3}'.format(a,b,c,m)) print('sum from 1 to n', T(n,a,b,c,m)) def U(n,a,b,c,m): S = 0 for i in range(1,n+1): j = i if i%2==0: j = i//2 S += f(a,b,c,m,j) if j!=i: S

Questions about programming?Chat with your personal AI assistant