All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Another Man's Floor (Posted on 2005-11-23) Difficulty: 4 of 5
Let a, b, and m be positive whole numbers. Required is a fast algorithm for evaluating Σk=0..m floor(ka/b), floor(x) being the greatest integer that does not exceed the real number x.

See The Solution Submitted by Richard    
Rating: 4.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
A contribution | Comment 2 of 11 |

Same basic idea as eg.

write a= xb + r (0 <= r <b )

Then rewrite as a/b = x + r/b = x + y/z where y/z is r/b reduced so that y and z are co-prime (no common divisors other than 1).

(Edit: x,y and z are of course non-negative integers, z>0)

Now summing k = 0...m.

sum(ka/b)=sum(xk) + sum (ky/z)

= x sum(k) + y sum(k/z)

Using notation [x] = floor(x)...

sum( [ ka/b] ) = (x/2) (m)(m+1) + y sum( [k/z] ) since now it only matters if z divides k.  I think this is summable and will try later but have no objection is someone finds it first.

Edited on November 23, 2005, 6:16 pm
  Posted by goFish on 2005-11-23 18:11:09

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (25)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information