W
Walter Roberson
long division uses O(n^2) time or worse for large n),
And much *much* worse time when dividing by 0 ;-)
And much *much* worse time when dividing by 0 ;-)
Chris Croughton said:If you can divide 1639657633472406784 by 7 in your head reliably, go for
it! I can't, reliably, so I prefer rules which are simple and use O(n)
time (long division uses O(n^2) time or worse for large n), like the sum
of the digits modulo 3 == 0 for multiples of 3 (multiples of 2, 5 and 10
are even faster, being O(1)).
Gorgeous. You can even do this:
while (condition) {
/* stuff */
} while (condition);
For bonus points, make sure that you leave the first loop with break -
at the precise moment that the condition is false.
Chris said:If you can divide 1639657633472406784 by 7 in your head reliably,
go for it! I can't, reliably, so I prefer rules which are simple
and use O(n) time (long division uses O(n^2) time or worse for
large n), like the sum of the digits modulo 3 == 0 for multiples
of 3 (multiples of 2, 5 and 10 are even faster, being O(1)).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.