mersenneforum.org > Math Fast way to square???
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 2004-05-28, 16:26 #1 maheshexp   May 2004 52 Posts Fast way to square??? can any one help me to find out wheather it multiples faster to get the "square of a number i.e x^2 "or not. if you have better solution , could u please give me. y(1) = 1; y(n) = y(n-1) + ( 1 + 2* (n-1)), n > 1 eg: to find 4^2 y(1) = 1 y(2) = y(1) + (1 + 2*(1)) => 4 y(3) = y(2) + (1 + 2*(2)) => 9 y(4) = y(3) + (1 + 2*(3)) => 16 A CPP Program.... Code: `void test2() { long long max = 60000; long long y = 1; time_t t1, t2; time(&t1); for (long long j = 0; j < max / 3; j++) for (long long i = 1; i <= max; i++) { y = i * i; } time(&t2); cout<<"muls:\n\t"<<"t1:" << t1 << "\n\tt2:" <
 2004-05-28, 16:58 #2 dave_dm   May 2004 24·5 Posts The algorithm you've given is probably close to optimal for computing the square of all integers 1 <= x <= max. However, if you only want the square of only one number then straightforward multiplication is much quicker. For the range 1 <= x <= 60000, there is no quicker way to square a number than just "y = x * x;" For larger numbers whose squares don't fit in a word, there are more efficient algorithms. A description of many of them is given on Carey Bloodworth's page
 2004-05-29, 01:54 #3 maheshexp   May 2004 110012 Posts thanks friend...what u say is right... does any thing could be done faster using the binary techniques

 Similar Threads Thread Thread Starter Forum Replies Last Post jasong jasong 35 2016-12-11 00:57 Damian Math 3 2010-01-01 01:56 Fusion_power Puzzles 14 2008-04-25 11:37 davar55 Puzzles 34 2007-06-12 14:17 Zeta-Flux Math 16 2005-12-14 06:55

All times are UTC. The time now is 04:56.

Mon Mar 30 04:56:19 UTC 2020 up 5 days, 2:29, 2 users, load averages: 1.20, 1.28, 1.48