<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Some Kind of Blog or Something</title>
<link>https://your-website-url.example.com/</link>
<atom:link href="https://your-website-url.example.com/index.xml" rel="self" type="application/rss+xml"/>
<description>idek bro</description>
<generator>quarto-1.8.26</generator>
<lastBuildDate>Sat, 11 Apr 2026 07:00:00 GMT</lastBuildDate>
<item>
  <title>Multiples of 3 or 5</title>
  <dc:creator>D.E. Manzanares</dc:creator>
  <link>https://your-website-url.example.com/posts/multiples-of-3-or-5/</link>
  <description><![CDATA[ 






<p>This article investigates arithmetic sequences and series from a few different perspectives, and ends by touching on the inclusion-exclusion principle.</p>
<p>This article includes code snippets, however, they reveal no information that is not already discussed in prose. If you have no interest in the code, the snippets can be skipped without any loss of continuity.</p>
<p>The contents should be accessible (and hopefully interesting as well) to those ranging from late high-school to early undergraduate. There is nothing super complicated here—just a little arithmetic and a little logic.</p>
<section id="multiples-of-3-or-5" class="level1">
<h1>Multiples of 3 or 5</h1>
<p>From <a href="https://projecteuler.net/problem=1">#1 Multiples of 3 or 5 - Project Euler</a></p>
<blockquote class="blockquote">
<p>
If we list all the natural numbers below <img src="https://latex.codecogs.com/png.latex?10"> that are multiples of <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5">, we get <img src="https://latex.codecogs.com/png.latex?3,%205,%206"> and <img src="https://latex.codecogs.com/png.latex?9">. The sum of these multiples is <img src="https://latex.codecogs.com/png.latex?23">.
</p>
<p>
Find the sum of all the multiples of <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5"> below <img src="https://latex.codecogs.com/png.latex?1000">.
</p>
</blockquote>
<p>One of the first things that comes to mind is to check every natural number in <img src="https://latex.codecogs.com/png.latex?%5B3,1000)"> for divisibility by <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5">. We are checking <img src="https://latex.codecogs.com/png.latex?n"> numbers for divisibility by <img src="https://latex.codecogs.com/png.latex?m"> divisors, so the time complexity of this algorithm is <img src="https://latex.codecogs.com/png.latex?O(n%5C,m)">.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="lst-1" style="background: #f1f3f5;"><pre class="sourceCode cpp code-with-copy"><code class="sourceCode cpp"><span id="lst-1-1">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Check-Every-Number Algorithm</span></span>
<span id="lst-1-2">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{};</span></span>
<span id="lst-1-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="lst-1-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="lst-1-5">      sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="lst-1-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="lst-1-7">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="lst-1-8">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">std::</span>cout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 233168</span></span></code></pre></div></div>
<p>That works! But, there is another way to think about the problem…</p>
</section>
<section id="arithmetic-series" class="level1 page-columns page-full">
<h1>Arithmetic series</h1>
<p>Enumerating the multiples of <img src="https://latex.codecogs.com/png.latex?3"> in <img src="https://latex.codecogs.com/png.latex?%5B3,1000)"> gives the finite arithmetic sequence</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A3,6,9,%5Cdots,999.%0A"></p>
<p>An <em>arithmetic sequence</em> is an ordered list of numbers where every next number is generated by adding a constant to the previous number. This constant, say <em>d</em>, is known as the common difference. In the case of our sequence of multiples of three, our first element is <img src="https://latex.codecogs.com/png.latex?3"> and we generate every next element by adding <img src="https://latex.codecogs.com/png.latex?d=3"> to the previous element.</p>
<p>There is a well-known closed-form<sup><img src="https://latex.codecogs.com/png.latex?%5Ctext%7B*%7D"></sup> expression to calculate the sum of a finite arithmetic sequence:</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><sup><img src="https://latex.codecogs.com/png.latex?%5Ctext%7B*%7D"></sup> “Closed-form” meaning an expression of a constant number of arithmetic operations, as opposed to the <img src="https://latex.codecogs.com/png.latex?n-1"> arithmetic operations when summing any old collection of <em>n</em> numbers: <img src="https://latex.codecogs.com/png.latex?x_1+x_2+%5Cdots+x_%7Bn-1%7D+x_n">.</p>
</div></div><p><span id="eq-1"><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn%7Da_i%20%20=%20%5Cleft(%5Cfrac%7Ba_1+a_n%7D%7B2%7D%5Cright)n%5C,.%0A%5Ctag%7B1%7D"></span></p>
<p>So, the sum of all multiples of <img src="https://latex.codecogs.com/png.latex?3"> below <img src="https://latex.codecogs.com/png.latex?1000"> is</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cfrac%7B3+999%7D%7B2%7D%5Cright)333%20=%20166833.%0A"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p>We know that there are <img src="https://latex.codecogs.com/png.latex?333"> elements in the sequence because <img src="https://latex.codecogs.com/png.latex?(1000-1)//3=333">.</p>
</div><div class="">
<p><img src="https://latex.codecogs.com/png.latex?//"> means integer division. Divide then discard the fractional part. <img src="https://latex.codecogs.com/png.latex?3/2=1.5,%5C,3//2=1">.</p>
</div></div>
<p>We can verify the result with our check-every-number algorithm:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode cpp code-with-copy"><code class="sourceCode cpp"><span id="cb1-1">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Check-Every-Number Algorithm</span></span>
<span id="cb1-2">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{};</span></span>
<span id="cb1-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-5">      sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb1-7">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb1-8">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">std::</span>cout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 166833</span></span></code></pre></div></div>
<p>Cool! But, why does this work? Let’s examine each of the terms in the expression <img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cdfrac%7Ba_1+a_n%7D%7B2%7D%5Cright)n">.</p>
<section id="building-intuition" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="building-intuition">Building intuition</h2>
<section id="arithmetic-mean" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="arithmetic-mean">Arithmetic mean</h3>
<p>You may have noticed that the term <img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7Ba_1+a_n%7D%7B2%7D"> resembles the form of an average—or more precisely—an arithmetic mean. It is the average of <img src="https://latex.codecogs.com/png.latex?a_1"> and <img src="https://latex.codecogs.com/png.latex?a_n">, and is also—perhaps surprisingly—the average of any arithmetic sequence starting with <img src="https://latex.codecogs.com/png.latex?a_1"> and ending with <img src="https://latex.codecogs.com/png.latex?a_n">. In other words, the average of a collection of numbers <img src="https://latex.codecogs.com/png.latex?a_1"> through <img src="https://latex.codecogs.com/png.latex?a_n"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p>Here, average is used to mean arithmetic mean.</p>
</div></div><p><img src="https://latex.codecogs.com/png.latex?%0A%5Coverline%7Ba%7D%20=%20%5Cfrac%7B1%7D%7Bn%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20a_i%20=%20%5Cfrac%7Ba_1+a_2+a_3+%5Cdots+a_%7Bn-1%7D+a_%7Bn-1%7D+a_n%7D%7Bn%7D%0A"> can be shortened to <img src="https://latex.codecogs.com/png.latex?%0A%5Coverline%7Ba%7D=%20%5Cfrac%7Ba_1+a_n%7D%7B2%7D%0A"> in the special case that <img src="https://latex.codecogs.com/png.latex?a_1"> through <img src="https://latex.codecogs.com/png.latex?a_n"> form an arithmetic sequence. Why?</p>
<p>We can think of an average as a sort of center; a point of balance; a center of mass. Imagine the numbers in a sequence to be objects of uniform mass, fixed to a rigid pole at positions corresponding to their positions on the number line. For the sequence <img src="https://latex.codecogs.com/png.latex?%5C%7B-1,1%5C%7D">, our point of balance would be <img src="https://latex.codecogs.com/png.latex?0">.</p>
<center>
<img src="https://your-website-url.example.com/posts/multiples-of-3-or-5/number_line_-1_1.png" class="img-fluid">
</center>
<p>
</p>
<p>We can fix as many of these objects as we like to this pole and keep the center of balance at <img src="https://latex.codecogs.com/png.latex?0">; so long as we place objects in pairs equidistant and on opposite sides from <img src="https://latex.codecogs.com/png.latex?0">, or place the objects directly at the center of balance. For example, extending the sequence <img src="https://latex.codecogs.com/png.latex?%5C%7B-1,1%5C%7D"> with the numbers <img src="https://latex.codecogs.com/png.latex?%5C%7B-%5Cfrac%7B3%7D%7B5%7D,%5Cfrac%7B3%7D%7B5%7D%5C%7D,%5C%7B-%5Cfrac%7B1%7D%7B2%7D,%5Cfrac%7B1%7D%7B2%7D%5C%7D,%5C%7B-%5Cfrac%7B1%7D%7B3%7D,%5Cfrac%7B1%7D%7B3%7D%5C%7D,%5C%7B-%5Cfrac%7B1%7D%7B5%7D,%5Cfrac%7B1%7D%7B5%7D%5C%7D">, and <img src="https://latex.codecogs.com/png.latex?%5C%7B0%5C%7D"> maintains balance at <img src="https://latex.codecogs.com/png.latex?0">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B-1-%5Cfrac%7B3%7D%7B5%7D-%5Cfrac%7B1%7D%7B2%7D-%5Cfrac%7B1%7D%7B3%7D-%5Cfrac%7B1%7D%7B5%7D+0+%5Cfrac%7B1%7D%7B5%7D+%5Cfrac%7B1%7D%7B3%7D+%5Cfrac%7B1%7D%7B2%7D+%5Cfrac%7B3%7D%7B5%7D+1%7D%7B11%7D%20=%20%5Cfrac%7B0%7D%7B11%7D%20=%200.%0A"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p>These numbers are the Farey sequence of order five transformed to fit the number line example: <img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cmathcal%7BF%7D_5-%5Cfrac%7B1%7D%7B2%7D%5Cright)%5Ccdot%202">.</p>
</div><div class="">
<p>Farey sequences have the property that we are exploring with the number line example: no matter how many elements there are in the sequence, they are constructed in such a way that the arithmetic mean of any Farey Sequence is <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B2%7D">.</p>
</div></div>
<p>This is exactly the type of balance we see in arithmetic sequences. Because every element in an arithmetic sequence is equidistant from its neighbors—leaning back on our analogy of center of mass—it’s not too far fetched to imagine that, where ever the center of the sequence is, there will be an equal number of elements on either side of that center, and the elements will be “balanced” in their distance from the center.</p>
<p>If we know the bounds of a sequence—the first and last elements—and know that all other elements of the sequence come in pairs balanced around the center, or at the center, then we do not need to know how many other elements there are, or what their exact values are, in order to find the center of the sequence. We may make an educated guess that the center will be exactly halfway between the first and last elements.</p>
<p>And so, we have made some sense of the term <img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7Ba_1+a_n%7D%7B2%7D">.</p>
<p>Looking back on Equation&nbsp;1 and having made some sense of the term representing the average of an arithmetic sequence, we now ask: why do we multiply the average of the sequence by the number of terms in the sequence to arrive at the sum?</p>
<p>Join me, again, in an exercise in imagination.</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><img src="https://your-website-url.example.com/posts/multiples-of-3-or-5/spongebob_imagination.png" class="img-fluid"> If you aren’t familiar with SpongeBob please excuse my misplaced humor.</p>
</div></div></section>
<section id="arithmetic-mean-times-n" class="level3">
<h3 class="anchored" data-anchor-id="arithmetic-mean-times-n">Arithmetic mean times <img src="https://latex.codecogs.com/png.latex?n"></h3>
<p>Imagine the numbers in a sequence <img src="https://latex.codecogs.com/png.latex?a_1,%20a_2,%5Cdots,a_n"> to be rectangles of a height <img src="https://latex.codecogs.com/png.latex?a_i"> and of width 1. The sequence <img src="https://latex.codecogs.com/png.latex?%5C%7B1,2,3%5C%7D"> could then be visualized as in the left most of the two figures below.</p>
<div style="display: flex; justify-content: center; gap: 20px;">
<p><img src="https://your-website-url.example.com/posts/multiples-of-3-or-5/bar_chart_123.png" width="350"> <img src="https://your-website-url.example.com/posts/multiples-of-3-or-5/bar_chart_222.png" width="350"></p>
</div>
<p>What is the total area of the rectangles in the collection on the left? The area of a rectangle is, of course, width <img src="https://latex.codecogs.com/png.latex?w"> by height <img src="https://latex.codecogs.com/png.latex?h">, and all widths here are <img src="https://latex.codecogs.com/png.latex?1">, so the area of the <img src="https://latex.codecogs.com/png.latex?i%5E%7Bth%7D"> rectangle is equal to its height <img src="https://latex.codecogs.com/png.latex?A_i%20=%20h_i%20=%20a_i">. The total area of the rectangles in the sequence <img src="https://latex.codecogs.com/png.latex?%5C%7B1,2,3%5C%7D"> is <img src="https://latex.codecogs.com/png.latex?1+2+3=6">.</p>
<p>Now, imagine that we want to “flatten” our collection of rectangles so that they are all of equal height, but whenever we push down on one rectangle, another rectangle of our choosing must rise an equal distance, so that total area of the collection is preserved. Easy enough: we can push down the third rectangle a distance of <img src="https://latex.codecogs.com/png.latex?1"> and allow the first rectangle to rise by a distance of <img src="https://latex.codecogs.com/png.latex?1">. Our collection now looks like the rightmost of the two figures above, and—as we know from the rules of the game—the total area of the rectangles is still <img src="https://latex.codecogs.com/png.latex?6">.</p>
<p>The uniform height of the rectangles after the flattening game is equal to the average height of the original rectangles <img src="https://latex.codecogs.com/png.latex?(1+2+3)/3=2">. The area of the collection, before and after flattening, is equal to that average height times the number of rectangles <img src="https://latex.codecogs.com/png.latex?2*3=6">. And so it is for any collection of rectangles we play this game with.</p>
<p>Stepping away from the rectangle analogy, the previous paragraph becomes: the sum of a collection of numbers is equal to the average of that collection times the number of elements in the collection. This claim is simple to prove:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aa_1+a_2+%5Cdots+a_n%20=%20%5Cleft(%5Cfrac%7Ba_1+a_2+%5Cdots+a_n%7D%7Bn%7D%5Cright)%20n%20.%0A"></p>
<p>And so, we have an idea why we multiply the average <img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7Ba_1+a_n%7D%7B2%7D"> by the count <img src="https://latex.codecogs.com/png.latex?n"> to arrive at the sum.</p>
</section>
</section>
<section id="intuitive-justification" class="level2">
<h2 class="anchored" data-anchor-id="intuitive-justification">Intuitive justification</h2>
<p>Combining our conclusions from the previous two sections, our justification for Equation&nbsp;1 becomes something like:</p>
<p>The sum of a collection of numbers is equal to the average of the collection times the number of elements in the collection (as shown in <img src="https://latex.codecogs.com/png.latex?%5CS"> Arithmetic mean times <img src="https://latex.codecogs.com/png.latex?n">)</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn%7Da_i%20=%20a_1+a_2+%5Cdots+a_n%20=%20%5Cleft(%5Cfrac%7Ba_1+a_2+%5Cdots+a_n%7D%7Bn%7D%5Cright)%20n,%0A"></p>
<p>and in the special case that <img src="https://latex.codecogs.com/png.latex?a_1"> through <img src="https://latex.codecogs.com/png.latex?a_n"> form an arithmetic sequence, we can simplify the expression for the average of the sequence (as discussed in <img src="https://latex.codecogs.com/png.latex?%5CS"> Arithmetic mean)</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cfrac%7Ba_1+a_2+%5Cdots+a_n%7D%7Bn%7D%5Cright)%20n%20=%20%5Cleft(%5Cfrac%7Ba_1+a_n%7D%7B2%7D%5Cright)%20n.%0A"></p>
<p>Therefore, the sum of a finite arithmetic sequence starting with <img src="https://latex.codecogs.com/png.latex?a_1"> and ending with <img src="https://latex.codecogs.com/png.latex?a_n"> is</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn%7Da_i%20=%20%5Cleft(%5Cfrac%7Ba_1+a_n%7D%7B2%7D%5Cright)%20n.%0A"></p>
<p>We have arrived at Equation&nbsp;1!</p>
</section>
<section id="derivation" class="level2">
<h2 class="anchored" data-anchor-id="derivation">Derivation</h2>
<p>In addition to our analogy-based justification of the formula for the sum of a finite arithmetic series, we can derive it algebraically.</p>
<p>We know that an arithmetic sequence is an ordered list of numbers where every next number is generated by adding a constant to the previous number. Using this, we can describe any element in the sequence in terms of the first element plus some number of steps. The <img src="https://latex.codecogs.com/png.latex?n%5E%7Bth%7D"> element of an arithmetic sequence with common difference <img src="https://latex.codecogs.com/png.latex?d"> would be</p>
<p><span id="eq-2"><img src="https://latex.codecogs.com/png.latex?%0Aa_n=a_1+(n-1)%5C,d.%0A%5Ctag%7B2%7D"></span></p>
<p>To illustrate relationship, the sequence of multiples of three, starting with 3, can be written as: <img src="https://latex.codecogs.com/png.latex?%0A3+(1-1)%5Ccdot%203,%5Cquad%203+(2-1)%5Ccdot%203,%20%5Cquad%203+(3-1)%5Ccdot%203,%5Cquad%20%5Cdots,%5Cquad%203+(n-1)%5Ccdot%203.%0A"></p>
<p>Using Equation&nbsp;2, we have an algebraically convenient way to express the sum of an finite arithmetic sequence starting with <img src="https://latex.codecogs.com/png.latex?a_1"> ending with <img src="https://latex.codecogs.com/png.latex?a_n"> and having common difference <img src="https://latex.codecogs.com/png.latex?d">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aa_1+%5Cdots+a_n%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20a_1%20+%20(i-1)%5C,d%20.%0A"></p>
<p>It is from this point that we begin our attempt to derive Equation&nbsp;1:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%5Csum_%7Bi=1%7D%5E%7Bn%7D%20a_1%20+%20&amp;(i-1)d%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20a_1%20+%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(i-1)d%5C%5C%0A&amp;=%20na_1%20+%20d%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(i-1)%5C%5C%0A&amp;=%20na_1%20+%20d%20%5Cleft%5B(1-1)+(2-1)+(3-1)+%5Cdots+((n-2)-1)+((n-1)-1)+(n-1)%5Cright%5D%5C%5C%0A&amp;=%20na_1%20+%20d%20%5Cleft%5B(1-1)+(2-1)+(3-1)+%5Cdots+(n-3)+(n-2)+(n-1)%5Cright%5D%5C%5C%0A%5Cend%7Balign*%7D"></p>
<p>And here we come to a tricky step: folding the series onto itself. Notice that, as we list terms from <img src="https://latex.codecogs.com/png.latex?(1-1)"> to <img src="https://latex.codecogs.com/png.latex?(n-1)">, for every <img src="https://latex.codecogs.com/png.latex?(x-1)"> term we have in the first half of the series, we find an <img src="https://latex.codecogs.com/png.latex?(n-x)"> term in the second half of the series. Each of these pairs simplifies to <img src="https://latex.codecogs.com/png.latex?(n-x)+(x-1)=(n-1)">. Notice also, that there are <img src="https://latex.codecogs.com/png.latex?n"> terms in the series, and therefore <img src="https://latex.codecogs.com/png.latex?n/2"> of the aforementioned pairs in the series. In all, we simplify <img src="https://latex.codecogs.com/png.latex?n/2"> pairs to <img src="https://latex.codecogs.com/png.latex?(n-1)">, so we write</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A&amp;=%20na_1%20+%20d%20%5Cleft%5B(1-1)+(2-1)+(3-1)+%5Cdots+(n-3)+(n-2)+(n-1)%5Cright%5D%5C%5C%0A&amp;=%20na_1%20+%20d%20%5Cleft%5B(n-1)%5Cfrac%7Bn%7D%7B2%7D%5Cright%5D.%0A%5Cend%7Balign*%7D"></p>
<p>Remembering the equation for the <img src="https://latex.codecogs.com/png.latex?n%5E%7Bth%7D"> element of an arithmetic sequence (Equation&nbsp;2), we can clean up our final expression a bit:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0Ana_1%20+%20(n-1)%5Cfrac%7Bn%7D%7B2%7Dd%20&amp;=%20%5Cleft(%202a_1%20+%20(n-1)%20d%20%5Cright)%5Cfrac%7Bn%7D%7B2%7D%20%20%5C%5C%0A&amp;=%20%5Cleft(%20a_1%20+%20a_1%20+%20(n-1)%20d%20%5Cright)%5Cfrac%7Bn%7D%7B2%7D%20%20%5C%5C%0A&amp;=%20%5Cleft(%20a_1%20+%20a_n%5Cright)%5Cfrac%7Bn%7D%7B2%7D%20%20%5C%5C%0A&amp;=%20%5Cleft(%5Cfrac%7Ba_1+a_n%7D%7B2%7D%5Cright)n.%0A%5Cend%7Balign*%7D"></p>
<p>And so we have arrived at the familiar expression.</p>
</section>
<section id="proof" class="level2">
<h2 class="anchored" data-anchor-id="proof">Proof</h2>
<p>The derivation is a proof unto itself, but I thought it would be fun to include a proof with mathematical induction. If you are unfamiliar with mathematical induction, that’s fine, just skim over the proof once, then look it over again as you read the following section: An explanation of mathematical induction.</p>
<p><em>Proposition.</em> If <img src="https://latex.codecogs.com/png.latex?a_1,%5Cdots,a_n"> is an arithmetic sequence of <img src="https://latex.codecogs.com/png.latex?n"> elements, then the sum of that sequence is</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn%7Da_i%20=%20%5Cfrac%7Ba_1+a_n%7D%7B2%7Dn.%0A"></p>
<p><em>Proof.</em> We know the proposition is true for <img src="https://latex.codecogs.com/png.latex?n=2">; we assume it is true for <img src="https://latex.codecogs.com/png.latex?%5C,n-1%5C,"> and prove it true for <img src="https://latex.codecogs.com/png.latex?n">.</p>
<p>We start by writing the series as</p>
<p><span id="eq-3"><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn%7Da_i%20=%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7Da_i%20+%20a_n%20=%20%5Cfrac%7Ba_1+a_%7Bn-1%7D%7D%7B2%7D(n-1)%20+%20a_n.%0A%5Ctag%7B3%7D"></span></p>
<p>But, we know that</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aa_%7Bn-1%7D=a_n-d%20%5Cquad%5Ctext%7Band%7D%5Cquad%20d=%5Cfrac%7Ba_n-a_1%7D%7Bn-1%7D,%0A"></p>
<p>so the expression becomes</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%5Cfrac%7Bn-1%7D%7B2%7D%5Cleft(a_1+a_%7Bn-1%7D%20%5Cright)+%20a_n%20&amp;=%20%5Cfrac%7Bn-1%7D%7B2%7D%5Cleft(a_1%20+%20a_n%20-%20%5Cfrac%7Ba_n-a_1%7D%7Bn-1%7D%5Cright)%20+%20a_n%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%7D%5Cleft(%5C,n%5C,(a_1+a_n)-1(a_1+a_n)-(a_n-a_1)+2a_n%5Cright)%20%5C%5C%0A&amp;=%20n%5C,%5Cfrac%7Ba_1+a_n%7D%7B2%7D.%20%5C%5C%0A%5Cend%7Balign*%7D"></p>
<div style="text-align: right;">
<p><img src="https://latex.codecogs.com/png.latex?%5Cblacksquare"></p>
</div>
<section id="an-explanation-of-mathematical-induction" class="level3">
<h3 class="anchored" data-anchor-id="an-explanation-of-mathematical-induction">An explanation of mathematical induction</h3>
<p>Mathematical induction, as used here, basically works as follows: We provide some base case for which the proposition is true. Then we show that, if we assume it is true for <img src="https://latex.codecogs.com/png.latex?n-1">, it must also be true for <img src="https://latex.codecogs.com/png.latex?n">.</p>
<p>In the proof above, we assume the proposition is true for <img src="https://latex.codecogs.com/png.latex?n-1"> by equating</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi=1%7D%5E%7Bn-1%7Da_i%20%5Cquad%5Ctext%7Band%7D%5Cquad%20%5Cfrac%7Ba_1+a_%7Bn-1%7D%7D%7B2%7D(n-1).%0A"></p>
<p>Then we show that, under this assumption, the proposition also holds for <img src="https://latex.codecogs.com/png.latex?n">. After we have established these facts, we use our base case and inductive reasoning to conclude that the proposition holds for all natural numbers greater than our equal to our base case:</p>
<p>We know the proposition is true for the base case <img src="https://latex.codecogs.com/png.latex?n=2">. So, we let <img src="https://latex.codecogs.com/png.latex?2"> stand in for <img src="https://latex.codecogs.com/png.latex?n-1">. We know that it holds for <img src="https://latex.codecogs.com/png.latex?n=2">, so we know it holds for <img src="https://latex.codecogs.com/png.latex?n-1=2">; and because it holds for <img src="https://latex.codecogs.com/png.latex?n-1=2">, by the algebra in our proof, it must hold for <img src="https://latex.codecogs.com/png.latex?n=3">. Now that we have proven it holds for <img src="https://latex.codecogs.com/png.latex?n=3">, we equate <img src="https://latex.codecogs.com/png.latex?3"> and <img src="https://latex.codecogs.com/png.latex?n-1">. Our proposition is true for <img src="https://latex.codecogs.com/png.latex?n=3">, so we know it holds for <img src="https://latex.codecogs.com/png.latex?n-1=3">; and because it holds for <img src="https://latex.codecogs.com/png.latex?n-1=3">, by the algebra in our proof, it must hold for <img src="https://latex.codecogs.com/png.latex?n=4">. In this way, we build a ladder off into infinity, the integrity of every next rung being guaranteed by the integrity of the previous rung.</p>
</section>
</section>
<section id="a-second-solution" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="a-second-solution">A second solution</h2>
<p>Instead of checking every natural number in <img src="https://latex.codecogs.com/png.latex?%5B3,1000)"> for divisibility by <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5">, as we did in our first solution, we can concisely express the sum of all multiples of <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5"> below 1000 using Equation&nbsp;1:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cfrac%7B3+999%7D%7B2%7D%5Cright)333%20+%20%5Cleft(%5Cfrac%7B5+995%7D%7B2%7D%5Cright)199%20=%20266333.%0A"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p>We know there are <img src="https://latex.codecogs.com/png.latex?199"> elements in the sequence of multiples of five less than <img src="https://latex.codecogs.com/png.latex?1000"> because <img src="https://latex.codecogs.com/png.latex?(1000-1)//5=199">.</p>
</div></div><div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode cpp code-with-copy"><code class="sourceCode cpp"><span id="cb2-1">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{};</span></span>
<span id="cb2-2">  sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">333</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-3">  sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">995</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-4">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">std::</span>cout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 266333</span></span></code></pre></div></div>
<p>Welp…comparing this to our check-every-number algorithm, which gives <img src="https://latex.codecogs.com/png.latex?233168">, we can see that we have overcounted by a bit. Why?</p>
<p>Enumerating the multiples of <img src="https://latex.codecogs.com/png.latex?3"> and <img src="https://latex.codecogs.com/png.latex?5">, we see that the two sequences share some elements:</p>
<p><img src="https://latex.codecogs.com/png.latex?%203,6,9,12,%5Cunderline%7B15%7D,18,21,24,27,%5Cunderline%7B30%7D,%5Cdots%20"> <img src="https://latex.codecogs.com/png.latex?%205,10,%5Cunderline%7B15%7D,20,25,%5Cunderline%7B30%7D,%5Cdots%20"></p>
<p>These shared elements are being doubly counted: once in the sum of the multiples of <img src="https://latex.codecogs.com/png.latex?3">, and once in the sum of the multiples of <img src="https://latex.codecogs.com/png.latex?5">. So, we need to find the sum of all these shared numbers and subtract that from our total, so that they are counted only once and not twice.</p>
<p>How do we get a handle on these shared numbers? They are multiples of <img src="https://latex.codecogs.com/png.latex?3">, and they are multiples of <img src="https://latex.codecogs.com/png.latex?5">; in shorter words they are multiples of <img src="https://latex.codecogs.com/png.latex?3"> and <img src="https://latex.codecogs.com/png.latex?5">; in even shorter words, they are multiples of <img src="https://latex.codecogs.com/png.latex?15">. So, we need to subtract the sum of all multiples of <img src="https://latex.codecogs.com/png.latex?15"> less than <img src="https://latex.codecogs.com/png.latex?1000"> from our total:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cfrac%7B3+999%7D%7B2%7D%5Cright)333%20+%20%5Cleft(%5Cfrac%7B5+995%7D%7B2%7D%5Cright)199%20-%20%5Cleft(%5Cfrac%7B15+990%7D%7B2%7D%5Cright)66%20=%20233168.%0A"></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode cpp code-with-copy"><code class="sourceCode cpp"><span id="cb3-1">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{};</span></span>
<span id="cb3-2">  sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">333</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-3">  sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">995</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-4">  sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">990</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">66</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-5">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">std::</span>cout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 233168</span></span></code></pre></div></div>
<p>Nice!</p>
<p>Now, what if we were interested in a more general question? What about the sum of multiples of some collection of positive integers less than some positive limit? The first step is to move from two divisors to three divisors: find the sum of all multiples of <img src="https://latex.codecogs.com/png.latex?3"> or <img src="https://latex.codecogs.com/png.latex?5"> or <img src="https://latex.codecogs.com/png.latex?7"> below <img src="https://latex.codecogs.com/png.latex?1000">.</p>
<p>First, let’s get a confident result from our check-every-number algorithm:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode cpp code-with-copy"><code class="sourceCode cpp"><span id="cb4-1">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Check-Every-Number Algorithm</span></span>
<span id="cb4-2">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{};</span></span>
<span id="cb4-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">int</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb4-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb4-5">      sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-7">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-8">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">std::</span>cout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 271066</span></span></code></pre></div></div>
<p>The next question is: how do we treat the over-counted numbers? Now that we have three divisors, some numbers will be singly counted, some doubly so, and some triply so. Do we subtract the series of the pair-wise least common multiples <img src="https://latex.codecogs.com/png.latex?3%5Ccdot5=15">, <img src="https://latex.codecogs.com/png.latex?%5C,3%5Ccdot7=21">, and <img src="https://latex.codecogs.com/png.latex?%5C,5%5Ccdot7=35">? Or, do we subtract the series of the three-way least common multiple <img src="https://latex.codecogs.com/png.latex?3%5Ccdot5%5Ccdot7=105">? Maybe both?</p>
<p>The answer is found in a bit of discrete maths called the inclusion-exclusion principle. It directly addresses our problem of counting a thing once, and once only.</p>
<p>And it is here that the article ends abruptly.</p>
<p>I wrote most of this several months ago, and fully intended on investigating the inclusion exclusion principle, but kinda lost steam over time. Perhaps I’ll come back to it later.</p>


</section>
</section>

 ]]></description>
  <guid>https://your-website-url.example.com/posts/multiples-of-3-or-5/</guid>
  <pubDate>Sat, 11 Apr 2026 07:00:00 GMT</pubDate>
</item>
</channel>
</rss>
