<div dir="ltr">That's why I warned about errors :).<br><br>Thanks for the catch.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 28, 2015 at 4:04 PM, Chaddaï Fouché <span dir="ltr"><<a href="mailto:chaddai.fouche@gmail.com" target="_blank">chaddai.fouche@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well I did it pretty dirty, not trying to simplify my solution (I'm skeptic of "k * n/k = n" given that this "n / k" is really "floor (n / k)" ... does this really work for you ?), this gave me :<br><br><span style="font-family:monospace,monospace">import Control.Monad (replicateM_)<br><br>main = do<br>    t <- readLn<br>    replicateM_ t (readLn >>= print . pe1 . subtract 1)<br><br>pe1 n = ( (3 + m3 * 3) * m3 + (5 + m5 * 5) * m5 - (15 + m15 * 15) * m15 ) `quot` 2<br>  where<br>    m3 = n `quot` 3<br>    m5 = n `quot` 5<br>    m15 = n `quot` 15</span><br><div class="gmail_extra"><br><br></div><div class="gmail_extra">Note that the sum of multiples of 3/5/15 can be seen as a sum of terms of an arithmetic sequence which is always "number of terms * (first term + last term) / 2", easily proven by the expedient of writing the sequence twice : one in the right order and the other in reverse under it, you then see that the sum of two term in column is always the same so ...<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra">-- <br></div><div class="gmail_extra">Jedaï<br></div></font></span></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>