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

  • SEARCH
  • Home
  • 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 8365589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:41:45+00:00 2026-06-09T12:41:45+00:00

The algorithm is taken from great Algorithms and Programming: Problems and Solutions by Alexander

  • 0

The algorithm is taken from great “Algorithms and Programming: Problems and Solutions” by Alexander Shen (namely exercise 1.1.28).

Following is my translation from Russian so excuse me for mistakes or ambiguity. Please correct me if you feel so.

What should algorithm do

With given natural n algorithm calculates the number of solutions of
inequality

x*x + y*y < n 

in natural (non-negative) numbers without using
manipulations on real numbers

In Pascal

k := 0; s := 0;

{at this moment of execution
 (s) = number of solutions of inequality with
 x*x + y*y < n, x < k}
while k*k < n do begin
  l := 0; t := 0;

  while k*k + l*l < n do begin
    l := l + 1;
    t := t + 1;
  end;

  {at this line 
   (t) = number of solutions of k*k + y*y < n
   for given (k) with y>=0}
  k := k + 1;
  s := s + t;
end;

{k*k >= n, so s = number of solutions of inequality}

Further in the text Shen says briefly that number of operations performed by this algorithm is “proportional to n, as one can calculate”. So I ask you how one can calculate that with strict mathematics.

  • 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-09T12:41:46+00:00Added an answer on June 9, 2026 at 12:41 pm

    You have two loops, one inside the other.

    The external has this condition: k*k < n so k goes from 0 up to SQRT(n)

    and the internal loop has this condition: k*k + l*l < n so l goes from 0 up to SQRT(n-k^2). But this is snaller than SQRT(n)

    So, the maximum iterations is less than SQRT(n) * SQRT(n) which is n and in every iteration a constant number of operations is done.

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

Sidebar

Related Questions

The following problem is taken from Problems on Algorithms (Problem 653): You are given
Hi I have the following bubble sort algorithm (generic code taken from another site)
Can the performance of this sequential search algorithm (taken from The Practice of Programming
Taken from Introduction to Algorithms Describe a Θ(n lg n)-time algorithm that, given a
I have this code for Jaro-Winkler algorithm taken from this website. I need to
This is a bit different. The following code was taken from a javascript script.
Evolutionary programming seems to be a great way to solve many optimization problems. The
Below is Porters Stemming Algorithm for JavaScript which I have taken from here: http://tartarus.org/~martin/PorterStemmer/js.txt
This code was taken from the book Haskell Road to Logic, Math and Programming.
I am using C++ and OpenCV to process some images taken from a Webcam

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.