here is the sample code of problem : a=100000000,b=200000; multiplication=1; while(a--){ multiplication=multiplication*b; } printf "multiplication= result" reduce the time complexity by giving a suitable example which must have less complexity than this for large numbers.
I was facing the same issue and I used this method for multiplication which reduces complexity to O(log n)
int calculatePower(int n,int p) { int h; if(p==0) { return 1; } else{ h=calculatePower(n,p/2); if(p%2==0) { return h*h; } else{ return n*h*h; } } }
Calculate 1+2+…+n without multiplication, division, key words for, while, if, else, switch, case, as well as conditional operator (A ? B : C).