Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8334761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:27:20+00:00 2026-06-09T03:27:20+00:00

A^2+B^2+C^2+D^2 = N Given an integer N , print out all possible combinations of

  • 0

A^2+B^2+C^2+D^2 = N Given an integer N, print out all possible combinations of integer values of ABCD which solve the equation.

I am guessing we can do better than brute force.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:27:22+00:00Added an answer on June 9, 2026 at 3:27 am

    The Wikipedia page has some interesting background information, but Lagrange’s four-square theorem (or, more correctly, Bachet’s Theorem – Lagrange only proved it) doesn’t really go into detail on how to find said squares.

    As I said in my comment, the solution is going to be nontrivial. This paper discusses the solvability of four-square sums. The paper alleges that:

    There is no convenient algorithm (beyond the simple one mentioned in
    the second paragraph of this paper) for finding additional solutions
    that are indicated by the calculation of representations, but perhaps
    this will streamline the search by giving an idea of what kinds of
    solutions do and do not exist.

    There are a few other interesting facts related to this topic. There
    exist other theorems that state that every integer can be written as a
    sum of four particular multiples of squares. For example, every
    integer can be written as N = a^2 + 2b^2 + 4c^2 + 14d^2. There are 54
    cases like this that are true for all integers, and Ramanujan provided
    the complete list in the year 1917.

    For more information, see Modular Forms. This is not easy to understand unless you have some background in number theory. If you could generalize Ramanujan’s 54 forms, you may have an easier time with this. With that said, in the first paper I cite, there is a small snippet which discusses an algorithm that may find every solution (even though I find it a bit hard to follow):

    For example, it was reported in 1911 that the calculator Gottfried
    Ruckle was asked to reduce N = 15663 as a sum of four squares. He
    produced a solution of 125^2 + 6^2 + 1^2 + 1^2 in 8 seconds, followed
    immediately by 125^2 + 5^2 + 3^2 + 2^2. A more difficult problem
    (reflected by a first term that is farther from the original number,
    with correspondingly larger later terms) took 56 seconds: 11399 = 105^2
    + 15^2 + 8^2 + 5^2. In general, the strategy is to begin by setting the first term to be the largest square below N and try to represent the
    smaller remainder as a sum of three squares. Then the first term is
    set to the next largest square below N, and so forth.
    Over time a
    lightning calculator would become familiar with expressing small
    numbers as sums of squares, which would speed up the process.

    (Emphasis mine.)

    The algorithm is described as being recursive, but it could easily be implemented iteratively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an integer array of size N by the user. Print all the possible
Given this code which prints all the bits in an integer out: private string
Given I have an integer value of, e.g., 10 . How can I create
I have written a program to find all the possible permutations of a given
I'm writing this function which I want to print all the sublists of a
Given an unsorted integer array, and without making any assumptions on the numbers in
Given a distance (50km) as integer: 50 And a time as string in the
Given a potentially huge integer value (in C# string format), I want to be
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Given this string random_string= '4' i want to determine if its an integer, a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.