Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Last active August 29, 2015 14:14
Show Gist options
  • Save amoshyc/77fdea53c90dcc82e600 to your computer and use it in GitHub Desktop.
Save amoshyc/77fdea53c90dcc82e600 to your computer and use it in GitHub Desktop.
Project Euler #1
所求
= sum([x for x in range(1, 1000) if x % 3 is 0 or x % 5 is 0])
= 3 的倍數和 + 5 的倍數和 - 15 的倍數和
= (3+6+...+999) + (5+10+...+995) - (15+30+...+990)
= ((3 + 999) * 333 / 2) + ((5 + 995) * 199 / 2) - ((15 + 990) * 66 / 2)
= 233168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment