![]() |
If your initial number = i and final number = f
i and f are boundary values of a series of consecutive odd numbers then sum = ( i + f ) / 2 * ( h - i + 2 ) / 2 i = 25 f = 29 sum = (25+29)/2 * (29-25+2)/2 sum = 27 * 3 sum = 81 It will work even in trivial cases i+2 = f i = 17 f = 19 --> 36 i = f i = 9 f = 9 --> 9 You still have to determine if this sum is a perfect square. There are tests that will eliminate a number as a perfect square ( if it isn't eliminated then it is a possible perfect square ) Other than doing a square root, squaring, then comparing I don't know any test that determines a number is a perfect square. Mapping the sum to the series 1..Z of odds would be another but the trick is to do the mapping. Will it involve more computations then the square root, square, compare. |
TravisT wisual proof of your statement would be really nice..:)
|
[quote="dsouza123"]If your initial number = i and final number = f
i and f are boundary values of a series of consecutive odd numbers then sum = ( i + f ) / 2 * ( f - i + 2 ) / 2 i = 25 f = 29 sum = (25+29)/2 * (29-25+2)/2 sum = 27 * 3 sum = 81[/quote] Here's a trick using Pythagorean triples to figure out the cases that are square. [b]EDIT - improved the method[/b] by using the fact the i and f are odd. Let a = ( f + 1)/2 and b = ( i - 1)/2 a and b are integers because f and i are odd. Then sum = (a+b)*(a-b) = (a^2 - b^2) We want the sum to be a perfect square, so we are looking for values that make a^2 - b^2 = c^2 b^2 + c^2 = a^2 So (b,c,a) is a Pythagorean Triple. It's known that Primitive Pythagorean Triples are of the form (p^2-q^2), (2pq), (p^2 + q^2) There isn't any reason for our Pythagorean triple to be primitive, though. So the values may be "d" times this. There are two ways to match up the smaller terms. = b might be equal to the even primitive or the odd primitive. Let's first consider the even case first. b=2dpq c=d(p^2-q^2) a=d(p^2+q^2) In the example, we know the initial value "i" is equal to 25. We also know that i = 2b+1 = 4dpq+1 25 = 4dpq+1 6=dpq. Keeping p>=q so that p^2-q^2 is non-negative, the possible values are [code:1] d p q 1 6 1 1 3 2 2 3 1 3 2 1[/code:1] We know the final value is f=2a-1=2d(p^2+q^2)-1. Calculating this for each case, we get final values of 73, 25, 39, 29, and 23. I don't know what to make of the 23, but the other final values result in sums that are perfect squares: 35^2, 5^2, 16^2, and 9^2. Trying the other matchup, with b=d(p+q)(p-q) did not generate any new final values. Assuming your interest is always sums of consecutive odd numbers, this appears to be a straight forward [b]way to determine, for a given initial value, all final values where the sum is a perfect square.[/b] The method could probably be adapted for sums of other arithemetic series. |
Before I try to figure out how to get a visual proof of this up, I would like to make sure that it's really what you want.
What I proved is only useful if the sequence is every other number (an arithmetic sequence with constant 2) which is what you gave in the example, but I don't know if you need a general case as well Also, if you need the smallest sum that equals a square for each sequence, what I figured out won't help you. If it's still useful, I'll go ahead and get the visuals ready |
may be you have still misunderstood my problem a little bit..
the question is about number of cycles or computations needed to know when will i get the perfect square.. In the perfect case I would need to now only 0th element and 1th element to tell how many elements will i need to reach a perfect square.. for example i know that 0th element is 14 and first element is 51(diferential is allways 2 so every next element will be constantly increased by two - 53, 55, 57, 59 etc..) so the question is can i tell how many element will i need to tell when the summ of the all string will be some natural n^2.. only knowing that 14 is the 0th element and 51 is the first element..(diferential is 2 as a rule).. of course in this case it is easy just to summ up element asnd calculate: 14+51=65; 65+53=118; 118+55=173; 173+57=230; 230+59=289=17^2 which is answer in this case.. But with large numbers it can need VERY MUCH cycles and lots of computations so i am looking for an ultimate method... Of course i am ready to receice any suggestions that would make such computations easier.. and thank you for your answers in any case |
One fairly quick method of finding square sums is to use [b]TravisT[/b]'s formula for the sum of a sequence of k odd terms starting at n: :idea: S = k^2 + k(n - 1).
:question: If n is a square, is {k = 1, S = n} a valid solution? First, try k = (n - 1)/3. if k is an integer, then S is a square. For large n, this probably won't be the first square sum. To find the first square S, keep a list of squares and 2*squares. i.e.: 4, 9, 16, 25, 36, 49, 64, 81, 100, ... 2, 8, 18, 32, 50, 72, 98, 128, 162, 200, ... If k is a square, and (k+n-1) is a square, then S is also a square. If k is 2*square, and (k+n-1) is 2*square, then S is also a square. The only solution I found which didn't fit these patterns was: n = 31, k = 24, k^2 + k(n-1) = 576 + 24*30 = 36^2 576 + 24*30 = 9(64 + 80) = 16(36 + 45) = 144(4 + 5) Fortunately, this was not the first square sum for n = 31. But we need a pattern that would tell us to check k = 24 in this case. The only things I see are: 1. k is a square times a factor of (n - 1) -> n - 1 = 5*6, k = 2*2*6. 2. k = 6*2^2 and (k + n - 1) = 6*3^2. Looking for the first pattern would introduce too many k values to try. And the second pattern means trying even more. :( For very large n, [b]wblipp[/b]'s solution is probably faster if you can code it to catch all combinations. |
yes.. those solutions may be faster that just summing up and checking.. but i think i will need a method to that finds how much elements will i need to get a perfect square.. If I want to check after every elemetn if the sum now is perfect square i doubt i will live long enough to wait while my test will finsh on REALLY large numbers...:)
|
[quote="Annunaki"]but i think i will need a method to that finds how much elements will i need to get a perfect square[/quote]
I think that my previous post does exactly that, and it has worked through the example for starting with 25. If you are having trouble following it, I'll work through a second example. What would like to use as the initial value in this new example? Pick something large enough to be interesting. |
let me see if I can translate the visual proof .. it's based on the fact that square numbers are the sums of odd numbers
so if you look at say, 11, you know that 1 + 3 + 5 + 7 + 9 + 11 is a square number (36) now, if you remove terms 1 through 9 and start an arithmetic sequence with 11, the sum of that sequence will always be 25 short of a square number, so once you get to 25 in the sequence, you can use it to fill in the first numbers in your sequence. so 11 + 13 + 15 + .. 23 + 25 = 1 + 3 + 5 + .. + 21 + 23 = 144 But if you started with 13, then 1 + 3 .. + 11 = 36, which is an even number, which will never show up in your sequence, so in that case, you need to find the 2 consecutive odd numbers that equal 36, to find them, you divide 36 by two, which is 18 and take the odd numbers on either side (17 + 19) so when your sequence reaches 19, it equals a square number so for a number [i]n[/i], if it leaves a remainder of 3 when you divide by 4 (like the 11 example) the last term in the sequence is (n-1)^2/4 if it leaves a remainder of 1, like the 13 example, the last number in the sequence is (n-1)^2/8+1 Now, for an even number, say, 12, you have to think of 12 + 14 + 16 + .. s (11 + 1) + (13 + 1) + (15 + 1) + ... in which case you have the same 11 + 13 + 15 + .. sequence we started with, plus an extra [i]k[/i] where [i]k[/i] is the number of terms, but you can think of every term as filling one more into the missing square left by 1 + 3 + 5 + 7 + 9 = 25, so it takes 25 terms to fill in that square. so the last term of the sequence if [i]n[/i] is even is n + (n-2)^2/4 - 2 .. Well, I wouldn't be surprised if this isn't exactly transparent .. I don't think I'm capable of lucidly explaining where I got the general forms, so I just left it out |
[b]wblipp[/b],
[b]Annunaki[/b] has introduced a 0th element, that needs to be included in the perfect square sum. Is there a way to do that with your method? If so, use { 9, 115 } -- 9 + 115 + 117 + ... = square. If not, use { i = 113 } If these are still too small use { 688, 4577 } and { i = 4321 } I want to be sure I understand how you generate all your valid solutions. |
[quote="Maybeso"][b]wblipp[/b],
[b]Annunaki[/b] has introduced a 0th element, that needs to be included in the perfect square sum. Is there a way to do that with your method? If so, use { 9, 115 } -- 9 + 115 + 117 + ... = square. If not, use { i = 113 } If these are still too small use { 688, 4577 } and { i = 4321 } I want to be sure I understand how you generate all your valid solutions.[/quote] I don’t see a way to include the zero term, although I’ll think about it. To make up for that, I’ll exhibit the larger case of i =4321. Define variables: a=(f+1)/2 and b= (i-1)/2 Show relationship SUM = a^2 – b^2 = c^2 Rearrange as Pythagorean Triple: b^2 + c^2 = a^2 Parameterize solution, picking b as the even primitive: Let b=2dpq, c=d(p^2-q^2), a=d(p^2+q^2) Knowing i, find all values of d, p, q with p>q i= 2b+1 =4dpq+1 4321 = 4dpq+1 4320 = 4dpq 1080 = dpq The prime factorization of 1080 is 2x2x2x3x3x3x5. There are 152 ways to pick d, p, and q with p>=q and the product equal to 1080. I listed these in a spreadsheet, and then also calculated the value for f = 2a-1 = 2d(p^2+q^2)-1, and I also calculated “c”, the square root of the sum, as c=d(p^2-q^2). The first line of this table is derived from d=1, p=36, and q=30. It tells us that if we sum from 4321 tp 4391, the total will be 396^2. [code:1] d p q f c 1 36 30 4391 396 1 40 27 4657 871 1 45 24 5201 1449 1 54 20 6631 2516 1 60 18 7847 3276 1 72 15 10817 4959 1 90 12 16487 7956 1 108 10 23527 11564 1 120 9 28961 14319 1 135 8 36577 18161 1 180 6 64871 32364 1 216 5 93361 46631 1 270 4 145831 72884 1 360 3 259217 129591 1 540 2 583207 291596 1 1080 1 2332801 1166399 2 27 20 4515 658 2 30 18 4895 1152 2 36 15 6083 2142 2 45 12 8675 3762 2 54 10 12063 5632 2 60 9 14723 7038 2 90 6 32543 16128 2 108 5 46755 23278 2 135 4 72963 36418 2 180 3 129635 64782 2 270 2 291615 145792 2 540 1 1166403 583198 3 20 18 4343 228 3 24 15 4805 1053 3 30 12 6263 2268 3 36 10 8375 3588 3 40 9 10085 4557 3 45 8 12533 5883 3 60 6 21815 10692 3 72 5 31253 15477 3 90 4 48695 24252 3 120 3 86453 43173 3 180 2 194423 97188 3 360 1 777605 388797 4 18 15 4391 396 4 27 10 6631 2516 4 30 9 7847 3276 4 45 6 16487 7956 4 54 5 23527 11564 4 90 3 64871 32364 4 135 2 145831 72884 4 270 1 583207 291596 5 18 12 4679 900 5 24 9 6569 2475 5 27 8 7929 3325 5 36 6 13319 6300 5 54 4 29319 14500 5 72 3 51929 25875 5 108 2 116679 58300 5 216 1 466569 233275 6 15 12 4427 486 6 18 10 5087 1344 6 20 9 5771 1914 6 30 6 11231 5184 6 36 5 15851 7626 6 45 4 24491 12054 6 60 3 43307 21546 6 90 2 97247 48576 6 180 1 388811 194394 8 15 9 4895 1152 8 27 5 12063 5632 8 45 3 32543 16128 8 135 1 291615 145792 9 12 10 4391 396 9 15 8 5201 1449 9 20 6 7847 3276 9 24 5 10817 4959 9 30 4 16487 7956 9 40 3 28961 14319 9 60 2 64871 32364 9 120 1 259217 129591 10 12 9 4499 630 10 18 6 7199 2880 10 27 4 14899 7130 10 36 3 26099 12870 10 54 2 58399 29120 10 108 1 233299 116630 12 10 9 4343 228 12 15 6 6263 2268 12 18 5 8375 3588 12 30 3 21815 10692 12 45 2 48695 24252 12 90 1 194423 97188 15 9 8 4349 255 15 12 6 5399 1620 15 18 4 10199 4620 15 24 3 17549 8505 15 36 2 38999 19380 15 72 1 155549 77745 18 10 6 4895 1152 18 12 5 6083 2142 18 15 4 8675 3762 18 20 3 14723 7038 18 30 2 32543 16128 18 60 1 129635 64782 20 9 6 4679 900 20 18 3 13319 6300 20 27 2 29319 14500 20 54 1 116679 58300 24 9 5 5087 1344 24 15 3 11231 5184 24 45 1 97247 48576 27 8 5 4805 1053 27 10 4 6263 2268 27 20 2 21815 10692 27 40 1 86453 43173 30 6 6 4319 0 30 9 4 5819 1950 30 12 3 9179 4050 30 18 2 19679 9600 30 36 1 77819 38850 36 6 5 4391 396 36 10 3 7847 3276 36 15 2 16487 7956 36 30 1 64871 32364 40 9 3 7199 2880 40 27 1 58399 29120 45 6 4 4679 900 45 8 3 6569 2475 45 12 2 13319 6300 45 24 1 51929 25875 54 5 4 4427 486 54 10 2 11231 5184 54 20 1 43307 21546 60 6 3 5399 1620 60 9 2 10199 4620 60 18 1 38999 19380 72 5 3 4895 1152 72 15 1 32543 16128 90 4 3 4499 630 90 6 2 7199 2880 90 12 1 26099 12870 108 5 2 6263 2268 108 10 1 21815 10692 120 3 3 4319 0 120 9 1 19679 9600 135 4 2 5399 1620 135 8 1 17549 8505 180 3 2 4679 900 180 6 1 13319 6300 216 5 1 11231 5184 270 2 2 4319 0 270 4 1 9179 4050 360 3 1 7199 2880 540 2 1 5399 1620 1080 1 1 4319 0[/code:1] Perhaps the most interesting linea in the table are that summing through 4319 results in a sum of zero. This makes sense in a perverse way – if you stop after 4319 you will stop before you start, and the sum will be zero. Counting zero, there are 74 different squares that are possible. |
| All times are UTC. The time now is 15:15. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.