-
Oct 4th, 2021, 10:41 AM
#1
Thread Starter
Hyperactive Member
Square decomposition brute force
Hi,
I am looking for something that shows me brute force square decomposition of number into multiline textbox. Something like - number 2104
0^2+4^2+18^2+42^2
0^2+18^2+22^2+36^2
2^2+4^2+22^2+40^2
2^2+8^2+10^2+44^2
2^2+10^2+20^2+40^2
2^2+16^2+20^2+38^2
2^2+20^2+26^2+32^2
4^2+16^2+26^2+34^2
6^2+12^2+18^2+40^2
6^2+12^2+30^2+32^2
6^2+14^2+24^2+36^2
8^2+10^2+28^2+34^2
I want to use the Double datatype since my target number is 744520332.
I want to use custom math.sqrt and floor functions, not built-in.
It will be good if solution will have an option for how much squares i.e 6,7,8,9,etc. Not powers, but number of numbers^2.
Thank you very much.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Oct 4th, 2021, 02:58 PM
#2
Re: Square decomposition brute force
Why the double data type? It seems like you'd just want to be using Long. After all, you aren't looking for any floating point math of any sort.
My usual boring signature: Nothing
-
Oct 4th, 2021, 03:42 PM
#3
Thread Starter
Hyperactive Member
Re: Square decomposition brute force
I am using Double basically everywhere (apart from few cases where I used BigInteger). I prior thought that Double is two times bigger than integer, but I wont noticed that it is floating point. Thus I would be OK with Long.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Oct 5th, 2021, 02:31 AM
#4
Re: Square decomposition brute force
I really don't understand your requirement about the number of squares the solution should contain.
A simple approach for finding the first sequence of numbers would be this (VB6 code, but should easily be adapted to any language)
Code:
Private Sub Command1_Click()
pSquareDecomposition 2104
pSquareDecomposition 67
pSquareDecomposition 34151
End Sub
Private Sub pSquareDecomposition(ByVal lValue As Long)
Dim lFindRoot As Long
Dim lRemainder As Long
Debug.Print lValue & ":",
lRemainder = lValue
Do While lRemainder > 0
lFindRoot = Int(Sqr(lRemainder))
Debug.Print lFindRoot,
lRemainder = lRemainder - (lFindRoot * lFindRoot)
Loop
Debug.Print
End Sub
2104: 45 8 3 2 1 1
67: 8 1 1 1
34151: 184 17 2 1 1
-
Oct 5th, 2021, 05:45 AM
#5
Thread Starter
Hyperactive Member
Re: Square decomposition brute force
Originally Posted by Arnoutdv
I really don't understand your requirement about the number of squares the solution should contain.
If I enter "6" into number of squares textbox, the software outputs your result:
2104: 45 8 3 2 1 1
2104: 42 18 4 0 0 0
etc.
In my first post it is with 4 squares.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Oct 5th, 2021, 07:06 AM
#6
Re: Square decomposition brute force
I still don't understand your goal.
You want an arbitrary number to be split in the sum of N squares?
Where do you need this for or is just some fun project?
-
Oct 5th, 2021, 08:09 AM
#7
Thread Starter
Hyperactive Member
Re: Square decomposition brute force
Yes and its just my personal project.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|