View Single Post
Old 05-16-2014, 12:07 AM   #256
reuben_tate
Kawaii Desu Ne?
Retired StaffFFR Veteran
 
reuben_tate's Avatar
 
Join Date: Dec 2007
Location: The Kawaiian Island~
Age: 30
Posts: 4,182
Default Re: The Project Euler thread

Decided to start doing this again. Going to start from the beginning because I know when I first started my solutions were crap. I used my favorite programming language for this one:


Some actual code:

Code:
/*
* We use the fact that 3+6+9+12+... = 3(1+2+3+..) from which we can
* use the n(n+1)/2 formula for the sum of the first n positve integers
*/
       int a = 999/3; //number of multiples of 3 less than 1000
       int b = 999/5; //number of multiples of 5 less than 1000
       int c = 999/15; //number of multiples of 15 less than 1000
       System.out.println(3*(a)*(a+1)/2+5*(b)*(b+1)/2-15*(c)*(c+1)/2);

__________________
AMA: http://ask.fm/benguino

Not happening now! Don't click to join!



Quote:
Originally Posted by Spenner View Post
(^)> peck peck says the heels
Quote:
Originally Posted by Xx{Midnight}xX
And god made ben, and realized he was doomed to miss. And said it was good.
Quote:
Originally Posted by Zakvvv666
awww :< crushing my dreams; was looking foward to you attempting to shoot yourself point blank and missing
reuben_tate is offline   Reply With Quote