Advertisement
GroggyOtter

Untitled

Apr 7th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /*
  2. Sum of all integers less than 1,000,000 that can be divided by the numbers 1 through 10 and have no remainder.
  3. The first number that meets this criteria is 2520. In total there are 397 numbers that meet this criteria. Format XXXXXXXXX
  4. */
  5.  
  6. ; End result. Start at 0
  7. result := 0
  8. ; Total number of instances found
  9. found := 0
  10.  
  11. ; Loop 999,999 times
  12. Loop, % (1000000 - 1)
  13. {
  14. ; Current number
  15. num := A_Index
  16.  
  17. ; Loop 9 times
  18. Loop, 9
  19. {
  20. ; Divide the current number by the current loop iteration+1 and get the remainder
  21. ; +1 because every number is divisible by 1. That's why we're looping 9 times instead of 10
  22. if (Mod(num, (A_Index+1)) != 0)
  23. ; If the remainder was not 0, break the loop
  24. Break
  25.  
  26. ; If you're able to get through all 9 loop iterations without breaking...
  27. if (A_Index = 9){
  28. ;...add the number to the end result
  29. result += num
  30. found++
  31. }
  32. }
  33. }
  34.  
  35. ; Display result to the user
  36. MsgBox, % "Number of instances found:`n" found "`n`nResult:`n" result
  37.  
  38. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement