Advertisement
Guest User

Untitled

a guest
Nov 29th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /* Square Remainder Challenge
  2. *
  3. * Here's a challenge for the math lovers. Solving this challenge can be done in 4 lines of code (inside of the method) but getting to the right solution can be tricky!
  4. *
  5. * Here we go:
  6. *
  7. * Let r be the remainder when (a−1)^n + (a+1)^n is divided by a^2.
  8. *
  9. * I.e., r = ((a−1)^n + (a+1)^n) % a^2
  10. *
  11. * Example: If a = 7 and n = 3,
  12. * then r = 42.
  13. * Because: ((7-1)^3 + (7+1)^3) % 7^2
  14. * = (6^3 + 8^3) % 49
  15. * = (216 + 512) % 49
  16. * = 728 % 49
  17. * = 42
  18. *
  19. * And as n varies, r will too, but for a = 7 it turns out that r_max = 42.
  20. *
  21. * You will receive two inputs to your method: a lower limit (integer) and an upper limit (integer).
  22. *
  23. * You need to make the Execute method return the SUM of r_max for:
  24. *
  25. * lowerLimit <= a <= upperLimit
  26. *
  27. * You will have to iterate over all possible values of a from the lower limit to the upper limit (including both limits).
  28. * Then, you need to add the r_max of each iteration to a sum, which your method shall return (integer).
  29. *
  30. * Good luck!
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement