How to enumerate x^2 + y^2 = z^2 - 1 (with additional constraints)

How to enumerate x^2 + y^2 = z^2 - 1 (with additional constraints)

Lets&nbsp;<code>N</code>&nbsp;be a number&nbsp;<code>(10&lt;=N&lt;=10^5)</code>.

Lets N be a number (10<=N<=10^5).

I have to break it into 3 numbers (x,y,z) such that it validates the following conditions.

1. x<=y<=z 
2. x^2+y^2=z^2-1;
3. x+y+z<=N

I have to find how many combinations I can get from the given numbers in a method.

I have tried as follows but it's taking so much time for a higher number and resulting in a timeout..

int N= Int32.Parse(Console.ReadLine());
List<String> res = new List<string>();

//x<=y<=z int mxSqrt = N - 2; int a = 0, b = 0; for (int z = 1; z <= mxSqrt; z++) { a = z * z; for (int y = 1; y <= z; y++) { b = y * y; for (int x = 1; x <= y; x++) { int x1 = b + x * x; int y1 = a - 1; if (x1 == y1 && ((x + y + z) <= N)) { res.Add(x + "," + y + "," + z); } } } } Console.WriteLine(res.Count());

My question:

My solution is taking time for a bigger number (I think it's the for loops), how can I improve it?

Is there any better approach for the same?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...