Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Sum of all integers less than 1,000,000 that can be divided by the numbers 1 through 10 and have no remainder.
- The first number that meets this criteria is 2520. In total there are 397 numbers that meet this criteria. Format XXXXXXXXX
- */
- ; End result. Start at 0
- result := 0
- ; Total number of instances found
- found := 0
- ; Loop 999,999 times
- Loop, % (1000000 - 1)
- {
- ; Current number
- num := A_Index
- ; Loop 9 times
- Loop, 9
- {
- ; Divide the current number by the current loop iteration+1 and get the remainder
- ; +1 because every number is divisible by 1. That's why we're looping 9 times instead of 10
- if (Mod(num, (A_Index+1)) != 0)
- ; If the remainder was not 0, break the loop
- Break
- ; If you're able to get through all 9 loop iterations without breaking...
- if (A_Index = 9){
- ;...add the number to the end result
- result += num
- found++
- }
- }
- }
- ; Display result to the user
- MsgBox, % "Number of instances found:`n" found "`n`nResult:`n" result
- ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement