Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

306 lines (292 sloc) 13.846 kb
<!DOCTYPE html>
<html data-require="math math-format word-problems subhints">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Divisibility tests</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="FACTOR">0</var>
<!-- ensure equal probability of yes or no -->
<var id="DIVISIBLE">randFromArray([true, false])</var>
<var id="NUMBER"
data-ensure="!DIVISIBLE ^ (NUMBER % FACTOR === 0)">
randRange(10000, 1000000)
</var>
</div>
<p class="question">
Is <code>\large{<var>NUMBER</var>}</code> divisible by
<code><var>FACTOR</var></code>?
</p>
<p class="solution"><var>DIVISIBLE ? "Yes" : "No"</var></p>
<ul class="choices" data-category="true">
<li>Yes</li>
<li>No</li>
</ul>
<div class="problems">
<div id="two" data-weight="1">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">2</var>
</div>
<div class="hints">
<p>Any even number is divisible by <code>2</code>.</p>
<p class="final_answer" data-if="DIVISIBLE">
<code><var>NUMBER</var></code> is even, so yes, it is
divisible by <code>2</code>.
</p>
<p class="final_answer" data-else>
<code><var>NUMBER</var></code> is odd, so it is
not divisible by <code>2</code>.
</p>
</div>
</div>
<div id="three" data-weight="2">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">3</var>
<var id="STEPS">(function(){
var steps = [];
var colors = [PINK, PURPLE, GREEN, BLUE];
var num = NUMBER;
var numColor = colors.pop();
while (num &gt; FACTOR * 11) {
var sumColor = colors.pop();
var digits = integerToDigits(num);
var sum = _.reduce(digits,
function(m, v) { return m + v; }, 0);
steps.push({
num: "\\color{" + numColor + "}{" + num + "}",
digits: _.map(digits, function(digit) {
return "\\color{" + numColor + "}{" +
digit + "}";
}),
sum: "\\color{" + sumColor + "}{" + sum + "}",
});
num = sum;
numColor = sumColor;
}
return steps;
})()</var>
</div>
<div class="hints">
<div>
<p>
A number is divisible by <code><var>FACTOR</var></code>
if the sum of its digits is divisible by
<code><var>FACTOR</var></code>.
[<a href="#" class="show-subhint"
data-subhint="explain-three">Why?</a>]
</p>
<div class="subhint" id="explain-three">
<p>
First, we can break the number up by place value:
</p>
<code>
\qquad\begin{eqnarray}
\blue{<var>NUMBER</var>}=
<var>integerToDigits(NUMBER).map(function(v, p) {
var placeValue = pow(10,
integerToDigits(NUMBER).length - p - 1);
return "&amp;&amp;\\blue{" + v + "}\\cdot" +
placeValue;
}).join("+ \\\\")</var>
\end{eqnarray}
</code>
<p>
Next, we can rewrite each of the place values as
<code>1</code> plus a bunch of <code>9</code>s:
</p>
<code>
\qquad\begin{eqnarray}
\blue{<var>NUMBER</var>}=
<var>integerToDigits(NUMBER).map(function(v, p) {
var placeValue = pow(10,
integerToDigits(NUMBER).length - p - 1);
if (placeValue === 1) {
return "&amp;&amp;\\blue{" + v + "}";
}
return "&amp;&amp;\\blue{" + v + "}(" +
(placeValue - 1) + "+1)";
}).join("+ \\\\")</var>
\end{eqnarray}
</code>
<p>
Now if we distribute and rearrange, we get this:
</p>
<code>
\qquad\begin{eqnarray}
\blue{<var>NUMBER</var>}=
<var>integerToDigits(NUMBER).map(function(v, p) {
var placeValue = pow(10,
integerToDigits(NUMBER).length - p - 1);
if (placeValue === 1) {
return "";
}
return "&amp;&amp;\\gray{" + v + "\\cdot" +
(placeValue - 1) + "}";
}).join("+ \\\\")</var>&amp;&amp;
\blue{<var>integerToDigits(NUMBER)
.join("}+\\blue{")</var>}
\end{eqnarray}
</code>
<p>
Any number consisting only of <code>9</code>s is
a multiple of <code><var>FACTOR</var></code>, so
the first <var>cardinal(integerToDigits(NUMBER)
.length - 1)</var> terms must all be multples of
<code><var>FACTOR</var></code>.
</p>
<p>
That means that to figure out whether the original
number is divisible by <code><var>FACTOR</var>
</code>, all we need to do is add up the digits
and see if the sum is divisible by
<code><var>FACTOR</var></code>. In other words,
<code>\blue{<var>NUMBER</var>}</code> is divisible
by <code><var>FACTOR</var></code> if <code>\blue{
<var>integerToDigits(NUMBER).join("}+\\blue{")
</var>}</code> is divisible by
<code><var>FACTOR</var></code>!
</p>
</div>
</div>
<div data-each="STEPS as N, STEP">
<p>Add the digits of <code><var>STEP.num</var></code>:</p>
<p style="margin-left: 20px;"><code>
<var>STEP.digits.join("+")</var> =
<var>STEP.sum</var>
</code></p>
<p style="margin-left: 20px;">
If <code><var>STEP.sum</var></code> is
divisible by <code><var>FACTOR</var></code>, then
<code><var>STEP.num</var></code> must also be
divisible by <code><var>FACTOR</var></code>.
</p>
</div>
<p class="final_answer" data-if="DIVISIBLE">
<code><var>_.last(STEPS).sum</var></code> is divisible
by <code><var>FACTOR</var></code>, therefore
<code>\blue{<var>NUMBER</var>}</code>
must also be divisible by <code><var>FACTOR</var></code>.
</p>
<p class="final_answer" data-else>
<code><var>_.last(STEPS).sum</var></code> is not divisible
by <code><var>FACTOR</var></code>, therefore
<code>\blue{<var>NUMBER</var>}</code>
must not be divisible by <code><var>FACTOR</var></code>.
</p>
</div>
</div>
<div id="four" data-weight="3">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">4</var>
</div>
<div class="hints">
<div>
<p>
A number is divisible by <code>4</code> if the last
two digits are divisible by <code>4</code>.
[<a href="#" class="show-subhint"
data-subhint="explain-four">Why?</a>]
</p>
<div class="subhint" id="explain-four">
<p>
We can rewrite the number as a multiple of
<code>100</code> plus the last two digits:
</p>
<code>\qquad
\gray{<var>NUMBER.toString().slice(0, -2)</var>}
\blue{<var>("00" + (NUMBER % 100)).slice(-2)</var>} =
\gray{<var>NUMBER.toString().slice(0, -2)</var>}
\gray{00} +
\blue{<var>("00" + (NUMBER % 100)).slice(-2)</var>}
</code>
<p>
Because <code><var>NUMBER.toString().slice(0, -2)
</var>00</code> is a multiple of <code>100</code>,
it is also a multiple of <code>4</code>.
</p>
<p>
So as long as the value of the last two digits,
<code>\blue{<var>NUMBER % 100</var>}</code>,
is divisible by <code>4</code>, the original
number must also be divisible by <code>4</code>!
</p>
</div>
</div>
<p>
Is the value of the last two digits,
<code><var>NUMBER % 100</var></code>,
divisible by <code>4</code>?
</p>
<p class="final_answer" data-if="DIVISIBLE">
Yes,
<code>\blue{<var>NUMBER % 100</var> \div 4 =
<var>NUMBER % 100 / 4</var>}</code>, so
<code><var>NUMBER</var></code> must also be divisible by
<code>4</code>.
</p>
<p class="final_answer" data-else>
No, <code><var>NUMBER % 100</var></code> is not
divisible by <code>4</code>, so
<code><var>NUMBER</var></code> is also not divisible by
<code>4</code>.
</p>
</div>
</div>
<div id="five" data-weight="1">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">5</var>
</div>
<div class="hints">
<p>
A number is divisible by <code>5</code> if the last
digit is a <code>0</code> or a <code>5</code>.
</p>
<p class="final_answer" data-if="DIVISIBLE">
The last digit of <code><var>NUMBER</var></code> is
<code><var>NUMBER % 10</var></code>, so yes
<code><var>NUMBER</var></code> is divisible by
<code>5</code>.
</p>
<p class="final_answer" data-else>
The last digit of <code><var>NUMBER</var></code> is
<code><var>NUMBER % 10</var></code>, so no
<code><var>NUMBER</var></code> is not divisible by
<code>5</code>.
</p>
</div>
</div>
<div id="nine" data-type="three" data-weight="2">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">9</var>
</div>
</div>
<div id="ten" data-weight="1">
<div class="vars" data-apply="appendVars">
<var id="FACTOR">10</var>
</div>
<div class="hints">
<p>
A number is divisible by <code>10</code> if the last
digit is a <code>0</code>.
</p>
<p class="final_answer" data-if="DIVISIBLE">
The last digit of <code><var>NUMBER</var></code> is
<code><var>NUMBER % 10</var></code>, so yes
<code><var>NUMBER</var></code> is divisible by
<code>10</code>.
</p>
<p class="final_answer" data-else>
The last digit of <code><var>NUMBER</var></code> is
<code><var>NUMBER % 10</var></code>, so no
<code><var>NUMBER</var></code> is not divisible by
<code>10</code>.
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.