How to test whether a number is of the form (n(n+1)(n+2))/ 6
Tetrahedral numbers (https://oeis.org/A000292) are:
1, 4, 10, 20, 35, 56, 84, etc
WHERE:
$$mathrm{Tetrahedral}(n) = frac{(n(n+1)(n+2))}{6}$$
But what is the test for whether a given number is a tetrahedral number?
I also need to know, if it is a tetrahedral number, then which term in the tetrahedral sequence is it? I am looking for a formula or something that would enable me to get these results:
input result ("is tetrahedral")
1 1
2 false
3 false
4 2
5 false
6 false
7 false
8 false
9 false
10 3
11 false
12 false
I can't find any formula on the Internet for this. Any pointers in the right direction would be great.
sequences-and-series
New contributor
add a comment |
Tetrahedral numbers (https://oeis.org/A000292) are:
1, 4, 10, 20, 35, 56, 84, etc
WHERE:
$$mathrm{Tetrahedral}(n) = frac{(n(n+1)(n+2))}{6}$$
But what is the test for whether a given number is a tetrahedral number?
I also need to know, if it is a tetrahedral number, then which term in the tetrahedral sequence is it? I am looking for a formula or something that would enable me to get these results:
input result ("is tetrahedral")
1 1
2 false
3 false
4 2
5 false
6 false
7 false
8 false
9 false
10 3
11 false
12 false
I can't find any formula on the Internet for this. Any pointers in the right direction would be great.
sequences-and-series
New contributor
1
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday
add a comment |
Tetrahedral numbers (https://oeis.org/A000292) are:
1, 4, 10, 20, 35, 56, 84, etc
WHERE:
$$mathrm{Tetrahedral}(n) = frac{(n(n+1)(n+2))}{6}$$
But what is the test for whether a given number is a tetrahedral number?
I also need to know, if it is a tetrahedral number, then which term in the tetrahedral sequence is it? I am looking for a formula or something that would enable me to get these results:
input result ("is tetrahedral")
1 1
2 false
3 false
4 2
5 false
6 false
7 false
8 false
9 false
10 3
11 false
12 false
I can't find any formula on the Internet for this. Any pointers in the right direction would be great.
sequences-and-series
New contributor
Tetrahedral numbers (https://oeis.org/A000292) are:
1, 4, 10, 20, 35, 56, 84, etc
WHERE:
$$mathrm{Tetrahedral}(n) = frac{(n(n+1)(n+2))}{6}$$
But what is the test for whether a given number is a tetrahedral number?
I also need to know, if it is a tetrahedral number, then which term in the tetrahedral sequence is it? I am looking for a formula or something that would enable me to get these results:
input result ("is tetrahedral")
1 1
2 false
3 false
4 2
5 false
6 false
7 false
8 false
9 false
10 3
11 false
12 false
I can't find any formula on the Internet for this. Any pointers in the right direction would be great.
sequences-and-series
sequences-and-series
New contributor
New contributor
edited yesterday
Mutantoe
566411
566411
New contributor
asked yesterday
danday74
1296
1296
New contributor
New contributor
1
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday
add a comment |
1
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday
1
1
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday
add a comment |
4 Answers
4
active
oldest
votes
Another way to look at that: $frac{n(n+1)(n+2)}{6}=frac{(n+1)^3-(n+1)}{6}$.
So then, if we have some $m$ we want to test? Multiply it by $6$. Add its cube root, rounded up - $k^3-k > (k-1)^3$ for all $k > 1$. If we get a perfect cube ($6m+lceilsqrt[3]{6m}rceil=k^3$ for some integer $k$), it's a tetrahedral number (Specifically, for $n=k-1$). If not, it isn't.
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
add a comment |
Notice that $n(n+1)(n+2)/6approx n^3/6$ for large values of $n$. Thus, if you have a suspected tetrahedral number $k$, and you compute $n_0=lfloorsqrt[3]{6k}rfloor$ you will have a pretty good guess as to which index you need to check to confirm or refute your suspicions.
This of course won't work for small $k$, and your initial guess $n_0$ need not be correct, but you have at least vastly reduced the number of operations you need to finish your problem. The full algorithm now would look something like this:
1) Take the input number $k$ and compute $n_0=lfloorsqrt[3]{6k}rfloor$.
2) If $text{Tetra}(n_0)>k$, begin testing all naturals $n<n_0$ (in decreasing order) until $text{Tetra}(n)leq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
3) If $text{Tetra}(n_0)<k$, begin testing all naturals $n>n_0$ until $text{Tetra}(n)geq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
4) If $text{Tetra}(n_0)=k$, then you are done, and the index is $n_0$.
New contributor
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
add a comment |
For a given $k$, you want to know if it exists an integer $n$ such that
$$frac{n(n+1)(n+2)}{6}=k$$ A simple way is to look at the cubic equation
$$n^3+3n^2+2n-6k=0$$ which has only one real root. Using the hyperbolic solution for this case, the solution is given by
$$n=-1+frac{2 }{sqrt{3}}cosh left(frac{1}{3} cosh ^{-1}left(9 sqrt{3},
kright)right)$$ If this $n$ is an integer (or very very close to because of possible rounding errors), then you are done.
If you prefer "simpler" analytical formulae, you also have
$$n=-1+t_1+t_2$$ where
$$t_1^3=frac{1}{3 left(sqrt{3} sqrt{243 k^2-1}+27 kright)}qquad text{and} qquad t_2^3=frac{1}{9} left(sqrt{3} sqrt{243 k^2-1}+27 kright)$$
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
add a comment |
Assume that $n(n+1)(n+2)/6=k$. Then $n(n+1)(n+2)-6k=0$, which has exactly one positive root for any positive $k$ (the left side increases monotonically and without bound from a negative intercept for positive $n$). If this is to be an integer then the rational root theorem guarantees that it will be a divisor of $6k$. So test such divisors in increasing order until you hit $n(n+1)(n+2)=6k$ or overshoot with $n(n+1)(n+2)>6k$.
We can cut down on trials by using the property that a tetrahedral number us the sum of alternating squares. With an odd argument the sum is $1^2+3^2+5^2+...$ with the sum truncated at the argument, thus the fifth nonzero terrahedral number is $1^2+3^2+5^2$. With an even argument we would use $2^2+4^2+6^2+...$.
If the argument $n$ is odd then, because all odd squares are $equiv 1bmod 8$, we must have $nequiv 2k-1bmod 8$. An even $n$ gives squares alternating between $4$ and $0bmod 8$, so if $k$ is divisible by $8$ then $nin{0,6}bmod 8$. If $k$ is instead four times an odd number then then $nin{2,4}bmod 8$.
Let's apply these ideas to $84$. This is four times an odd number, so an odd argument must be $equiv 7bmod 8$ and an even argument must be $in{2,4}bmod 8$. The divisors of $6×84=504$ satisfying these modular requirements are
$2,4,7,12,18,...,252$
We begin testing these in ascending order. We might see that $(8)(8+1)(8+2)>8^3>504$ (the cube root test in another answer), so either $2,4$ or $7$ works or else nothing does.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
danday74 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3060249%2fhow-to-test-whether-a-number-is-of-the-form-nn1n2-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Another way to look at that: $frac{n(n+1)(n+2)}{6}=frac{(n+1)^3-(n+1)}{6}$.
So then, if we have some $m$ we want to test? Multiply it by $6$. Add its cube root, rounded up - $k^3-k > (k-1)^3$ for all $k > 1$. If we get a perfect cube ($6m+lceilsqrt[3]{6m}rceil=k^3$ for some integer $k$), it's a tetrahedral number (Specifically, for $n=k-1$). If not, it isn't.
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
add a comment |
Another way to look at that: $frac{n(n+1)(n+2)}{6}=frac{(n+1)^3-(n+1)}{6}$.
So then, if we have some $m$ we want to test? Multiply it by $6$. Add its cube root, rounded up - $k^3-k > (k-1)^3$ for all $k > 1$. If we get a perfect cube ($6m+lceilsqrt[3]{6m}rceil=k^3$ for some integer $k$), it's a tetrahedral number (Specifically, for $n=k-1$). If not, it isn't.
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
add a comment |
Another way to look at that: $frac{n(n+1)(n+2)}{6}=frac{(n+1)^3-(n+1)}{6}$.
So then, if we have some $m$ we want to test? Multiply it by $6$. Add its cube root, rounded up - $k^3-k > (k-1)^3$ for all $k > 1$. If we get a perfect cube ($6m+lceilsqrt[3]{6m}rceil=k^3$ for some integer $k$), it's a tetrahedral number (Specifically, for $n=k-1$). If not, it isn't.
Another way to look at that: $frac{n(n+1)(n+2)}{6}=frac{(n+1)^3-(n+1)}{6}$.
So then, if we have some $m$ we want to test? Multiply it by $6$. Add its cube root, rounded up - $k^3-k > (k-1)^3$ for all $k > 1$. If we get a perfect cube ($6m+lceilsqrt[3]{6m}rceil=k^3$ for some integer $k$), it's a tetrahedral number (Specifically, for $n=k-1$). If not, it isn't.
answered yesterday
jmerry
2,066210
2,066210
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
add a comment |
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
implemented, works well in all test cases thx, but only returns a boolean (or am I doing something wrong?) - still very useful +1
– danday74
yesterday
1
1
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
So, I take it you didn't implement the part in the parenthetical comment that says which one it is?
– jmerry
23 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
with you now, I kinda follow what's going on - soooo clever! many thx - switching to this approach shaved 100ms off my code execution time
– danday74
22 hours ago
add a comment |
Notice that $n(n+1)(n+2)/6approx n^3/6$ for large values of $n$. Thus, if you have a suspected tetrahedral number $k$, and you compute $n_0=lfloorsqrt[3]{6k}rfloor$ you will have a pretty good guess as to which index you need to check to confirm or refute your suspicions.
This of course won't work for small $k$, and your initial guess $n_0$ need not be correct, but you have at least vastly reduced the number of operations you need to finish your problem. The full algorithm now would look something like this:
1) Take the input number $k$ and compute $n_0=lfloorsqrt[3]{6k}rfloor$.
2) If $text{Tetra}(n_0)>k$, begin testing all naturals $n<n_0$ (in decreasing order) until $text{Tetra}(n)leq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
3) If $text{Tetra}(n_0)<k$, begin testing all naturals $n>n_0$ until $text{Tetra}(n)geq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
4) If $text{Tetra}(n_0)=k$, then you are done, and the index is $n_0$.
New contributor
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
add a comment |
Notice that $n(n+1)(n+2)/6approx n^3/6$ for large values of $n$. Thus, if you have a suspected tetrahedral number $k$, and you compute $n_0=lfloorsqrt[3]{6k}rfloor$ you will have a pretty good guess as to which index you need to check to confirm or refute your suspicions.
This of course won't work for small $k$, and your initial guess $n_0$ need not be correct, but you have at least vastly reduced the number of operations you need to finish your problem. The full algorithm now would look something like this:
1) Take the input number $k$ and compute $n_0=lfloorsqrt[3]{6k}rfloor$.
2) If $text{Tetra}(n_0)>k$, begin testing all naturals $n<n_0$ (in decreasing order) until $text{Tetra}(n)leq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
3) If $text{Tetra}(n_0)<k$, begin testing all naturals $n>n_0$ until $text{Tetra}(n)geq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
4) If $text{Tetra}(n_0)=k$, then you are done, and the index is $n_0$.
New contributor
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
add a comment |
Notice that $n(n+1)(n+2)/6approx n^3/6$ for large values of $n$. Thus, if you have a suspected tetrahedral number $k$, and you compute $n_0=lfloorsqrt[3]{6k}rfloor$ you will have a pretty good guess as to which index you need to check to confirm or refute your suspicions.
This of course won't work for small $k$, and your initial guess $n_0$ need not be correct, but you have at least vastly reduced the number of operations you need to finish your problem. The full algorithm now would look something like this:
1) Take the input number $k$ and compute $n_0=lfloorsqrt[3]{6k}rfloor$.
2) If $text{Tetra}(n_0)>k$, begin testing all naturals $n<n_0$ (in decreasing order) until $text{Tetra}(n)leq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
3) If $text{Tetra}(n_0)<k$, begin testing all naturals $n>n_0$ until $text{Tetra}(n)geq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
4) If $text{Tetra}(n_0)=k$, then you are done, and the index is $n_0$.
New contributor
Notice that $n(n+1)(n+2)/6approx n^3/6$ for large values of $n$. Thus, if you have a suspected tetrahedral number $k$, and you compute $n_0=lfloorsqrt[3]{6k}rfloor$ you will have a pretty good guess as to which index you need to check to confirm or refute your suspicions.
This of course won't work for small $k$, and your initial guess $n_0$ need not be correct, but you have at least vastly reduced the number of operations you need to finish your problem. The full algorithm now would look something like this:
1) Take the input number $k$ and compute $n_0=lfloorsqrt[3]{6k}rfloor$.
2) If $text{Tetra}(n_0)>k$, begin testing all naturals $n<n_0$ (in decreasing order) until $text{Tetra}(n)leq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
3) If $text{Tetra}(n_0)<k$, begin testing all naturals $n>n_0$ until $text{Tetra}(n)geq k$. If you achieve equality, then $k$ is tetrahedral with index $n$. If you don't have equality, then $k$ is not tetrahedral.
4) If $text{Tetra}(n_0)=k$, then you are done, and the index is $n_0$.
New contributor
New contributor
answered yesterday
ItsJustASeriesBro
1563
1563
New contributor
New contributor
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
add a comment |
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
nice answer thx, works in all cases, very few iterations needed
– danday74
yesterday
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
other guy pipped you to post, his works without any iterations - but a superb answer, many thx - and a great generic approach to reducing iterations
– danday74
22 hours ago
add a comment |
For a given $k$, you want to know if it exists an integer $n$ such that
$$frac{n(n+1)(n+2)}{6}=k$$ A simple way is to look at the cubic equation
$$n^3+3n^2+2n-6k=0$$ which has only one real root. Using the hyperbolic solution for this case, the solution is given by
$$n=-1+frac{2 }{sqrt{3}}cosh left(frac{1}{3} cosh ^{-1}left(9 sqrt{3},
kright)right)$$ If this $n$ is an integer (or very very close to because of possible rounding errors), then you are done.
If you prefer "simpler" analytical formulae, you also have
$$n=-1+t_1+t_2$$ where
$$t_1^3=frac{1}{3 left(sqrt{3} sqrt{243 k^2-1}+27 kright)}qquad text{and} qquad t_2^3=frac{1}{9} left(sqrt{3} sqrt{243 k^2-1}+27 kright)$$
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
add a comment |
For a given $k$, you want to know if it exists an integer $n$ such that
$$frac{n(n+1)(n+2)}{6}=k$$ A simple way is to look at the cubic equation
$$n^3+3n^2+2n-6k=0$$ which has only one real root. Using the hyperbolic solution for this case, the solution is given by
$$n=-1+frac{2 }{sqrt{3}}cosh left(frac{1}{3} cosh ^{-1}left(9 sqrt{3},
kright)right)$$ If this $n$ is an integer (or very very close to because of possible rounding errors), then you are done.
If you prefer "simpler" analytical formulae, you also have
$$n=-1+t_1+t_2$$ where
$$t_1^3=frac{1}{3 left(sqrt{3} sqrt{243 k^2-1}+27 kright)}qquad text{and} qquad t_2^3=frac{1}{9} left(sqrt{3} sqrt{243 k^2-1}+27 kright)$$
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
add a comment |
For a given $k$, you want to know if it exists an integer $n$ such that
$$frac{n(n+1)(n+2)}{6}=k$$ A simple way is to look at the cubic equation
$$n^3+3n^2+2n-6k=0$$ which has only one real root. Using the hyperbolic solution for this case, the solution is given by
$$n=-1+frac{2 }{sqrt{3}}cosh left(frac{1}{3} cosh ^{-1}left(9 sqrt{3},
kright)right)$$ If this $n$ is an integer (or very very close to because of possible rounding errors), then you are done.
If you prefer "simpler" analytical formulae, you also have
$$n=-1+t_1+t_2$$ where
$$t_1^3=frac{1}{3 left(sqrt{3} sqrt{243 k^2-1}+27 kright)}qquad text{and} qquad t_2^3=frac{1}{9} left(sqrt{3} sqrt{243 k^2-1}+27 kright)$$
For a given $k$, you want to know if it exists an integer $n$ such that
$$frac{n(n+1)(n+2)}{6}=k$$ A simple way is to look at the cubic equation
$$n^3+3n^2+2n-6k=0$$ which has only one real root. Using the hyperbolic solution for this case, the solution is given by
$$n=-1+frac{2 }{sqrt{3}}cosh left(frac{1}{3} cosh ^{-1}left(9 sqrt{3},
kright)right)$$ If this $n$ is an integer (or very very close to because of possible rounding errors), then you are done.
If you prefer "simpler" analytical formulae, you also have
$$n=-1+t_1+t_2$$ where
$$t_1^3=frac{1}{3 left(sqrt{3} sqrt{243 k^2-1}+27 kright)}qquad text{and} qquad t_2^3=frac{1}{9} left(sqrt{3} sqrt{243 k^2-1}+27 kright)$$
edited yesterday
answered yesterday
Claude Leibovici
119k1157132
119k1157132
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
add a comment |
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
really appreciate your help, accepted other answer on the basis that usually only 2 iterations are needed and that this MAY be computationally more expensive - but I haven't tested performance and this MAY be faster - indeed, where performance is not an issue, this is undoubtedly a great answer
– danday74
23 hours ago
add a comment |
Assume that $n(n+1)(n+2)/6=k$. Then $n(n+1)(n+2)-6k=0$, which has exactly one positive root for any positive $k$ (the left side increases monotonically and without bound from a negative intercept for positive $n$). If this is to be an integer then the rational root theorem guarantees that it will be a divisor of $6k$. So test such divisors in increasing order until you hit $n(n+1)(n+2)=6k$ or overshoot with $n(n+1)(n+2)>6k$.
We can cut down on trials by using the property that a tetrahedral number us the sum of alternating squares. With an odd argument the sum is $1^2+3^2+5^2+...$ with the sum truncated at the argument, thus the fifth nonzero terrahedral number is $1^2+3^2+5^2$. With an even argument we would use $2^2+4^2+6^2+...$.
If the argument $n$ is odd then, because all odd squares are $equiv 1bmod 8$, we must have $nequiv 2k-1bmod 8$. An even $n$ gives squares alternating between $4$ and $0bmod 8$, so if $k$ is divisible by $8$ then $nin{0,6}bmod 8$. If $k$ is instead four times an odd number then then $nin{2,4}bmod 8$.
Let's apply these ideas to $84$. This is four times an odd number, so an odd argument must be $equiv 7bmod 8$ and an even argument must be $in{2,4}bmod 8$. The divisors of $6×84=504$ satisfying these modular requirements are
$2,4,7,12,18,...,252$
We begin testing these in ascending order. We might see that $(8)(8+1)(8+2)>8^3>504$ (the cube root test in another answer), so either $2,4$ or $7$ works or else nothing does.
add a comment |
Assume that $n(n+1)(n+2)/6=k$. Then $n(n+1)(n+2)-6k=0$, which has exactly one positive root for any positive $k$ (the left side increases monotonically and without bound from a negative intercept for positive $n$). If this is to be an integer then the rational root theorem guarantees that it will be a divisor of $6k$. So test such divisors in increasing order until you hit $n(n+1)(n+2)=6k$ or overshoot with $n(n+1)(n+2)>6k$.
We can cut down on trials by using the property that a tetrahedral number us the sum of alternating squares. With an odd argument the sum is $1^2+3^2+5^2+...$ with the sum truncated at the argument, thus the fifth nonzero terrahedral number is $1^2+3^2+5^2$. With an even argument we would use $2^2+4^2+6^2+...$.
If the argument $n$ is odd then, because all odd squares are $equiv 1bmod 8$, we must have $nequiv 2k-1bmod 8$. An even $n$ gives squares alternating between $4$ and $0bmod 8$, so if $k$ is divisible by $8$ then $nin{0,6}bmod 8$. If $k$ is instead four times an odd number then then $nin{2,4}bmod 8$.
Let's apply these ideas to $84$. This is four times an odd number, so an odd argument must be $equiv 7bmod 8$ and an even argument must be $in{2,4}bmod 8$. The divisors of $6×84=504$ satisfying these modular requirements are
$2,4,7,12,18,...,252$
We begin testing these in ascending order. We might see that $(8)(8+1)(8+2)>8^3>504$ (the cube root test in another answer), so either $2,4$ or $7$ works or else nothing does.
add a comment |
Assume that $n(n+1)(n+2)/6=k$. Then $n(n+1)(n+2)-6k=0$, which has exactly one positive root for any positive $k$ (the left side increases monotonically and without bound from a negative intercept for positive $n$). If this is to be an integer then the rational root theorem guarantees that it will be a divisor of $6k$. So test such divisors in increasing order until you hit $n(n+1)(n+2)=6k$ or overshoot with $n(n+1)(n+2)>6k$.
We can cut down on trials by using the property that a tetrahedral number us the sum of alternating squares. With an odd argument the sum is $1^2+3^2+5^2+...$ with the sum truncated at the argument, thus the fifth nonzero terrahedral number is $1^2+3^2+5^2$. With an even argument we would use $2^2+4^2+6^2+...$.
If the argument $n$ is odd then, because all odd squares are $equiv 1bmod 8$, we must have $nequiv 2k-1bmod 8$. An even $n$ gives squares alternating between $4$ and $0bmod 8$, so if $k$ is divisible by $8$ then $nin{0,6}bmod 8$. If $k$ is instead four times an odd number then then $nin{2,4}bmod 8$.
Let's apply these ideas to $84$. This is four times an odd number, so an odd argument must be $equiv 7bmod 8$ and an even argument must be $in{2,4}bmod 8$. The divisors of $6×84=504$ satisfying these modular requirements are
$2,4,7,12,18,...,252$
We begin testing these in ascending order. We might see that $(8)(8+1)(8+2)>8^3>504$ (the cube root test in another answer), so either $2,4$ or $7$ works or else nothing does.
Assume that $n(n+1)(n+2)/6=k$. Then $n(n+1)(n+2)-6k=0$, which has exactly one positive root for any positive $k$ (the left side increases monotonically and without bound from a negative intercept for positive $n$). If this is to be an integer then the rational root theorem guarantees that it will be a divisor of $6k$. So test such divisors in increasing order until you hit $n(n+1)(n+2)=6k$ or overshoot with $n(n+1)(n+2)>6k$.
We can cut down on trials by using the property that a tetrahedral number us the sum of alternating squares. With an odd argument the sum is $1^2+3^2+5^2+...$ with the sum truncated at the argument, thus the fifth nonzero terrahedral number is $1^2+3^2+5^2$. With an even argument we would use $2^2+4^2+6^2+...$.
If the argument $n$ is odd then, because all odd squares are $equiv 1bmod 8$, we must have $nequiv 2k-1bmod 8$. An even $n$ gives squares alternating between $4$ and $0bmod 8$, so if $k$ is divisible by $8$ then $nin{0,6}bmod 8$. If $k$ is instead four times an odd number then then $nin{2,4}bmod 8$.
Let's apply these ideas to $84$. This is four times an odd number, so an odd argument must be $equiv 7bmod 8$ and an even argument must be $in{2,4}bmod 8$. The divisors of $6×84=504$ satisfying these modular requirements are
$2,4,7,12,18,...,252$
We begin testing these in ascending order. We might see that $(8)(8+1)(8+2)>8^3>504$ (the cube root test in another answer), so either $2,4$ or $7$ works or else nothing does.
edited yesterday
answered yesterday
Oscar Lanzi
12.1k12036
12.1k12036
add a comment |
add a comment |
danday74 is a new contributor. Be nice, and check out our Code of Conduct.
danday74 is a new contributor. Be nice, and check out our Code of Conduct.
danday74 is a new contributor. Be nice, and check out our Code of Conduct.
danday74 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3060249%2fhow-to-test-whether-a-number-is-of-the-form-nn1n2-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hi & welcome to MSE. You could assume your number to test is a constant & $n$ is a variable, plug it into the equation for a tetrahedron # and solve for $n$ from the resulting $3$rd degree (i.e., cubic) polynomial.
– John Omielan
yesterday