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

int f(int a, int b, int c, int m, int i) { return (a*i*i+b*i+c)/m; } int T(int a, int b, int c, int m, int n) { int sum = 0; for(int i=0; i<=n; i++) sum += f(a, b, c, m, i); return sum; } int U(int a, int b, int c, int m, int n) { return T(a, b, c, m, n); } int main(void) { srand(time(NULL)); int a = (rand()%10)+1; int b = (rand()%10)+1; int c = (rand()%10)+1; int m = (rand()%10)+1; int n = (rand()%10)+1; int sum = U(a, b, c, m

Questions about programming?Chat with your personal AI assistant