Hello! I have an algorithm question.

Asked 2 years ago, Updated 2 years ago, 42 views

It's the following question, but I don't know how to solve it. How should I solve it? Masters, please answer!

algorithm java

2022-09-21 16:38

2 Answers

To solve the problem, you can think about it in two directions.

First, we'll have to think about finding a Tn that's smaller than the triangle K.

Let's roughly solve n(n+1)/2 < K with Tn = n(n+1)/2.

If we solve n(n+1) < 2K through the root solution of the quadratic equation, we get n< (sqrt(1+8K) - 1) / 2.

Through the stomach, we now know the trigonometric number n that makes the largest Tn less than K.

Second, when you add each triangle by choosing three numbers from the largest triangle 1 to n, you can think about how K is made.


2022-09-21 16:38

The simplest solution is

For input value N,


2022-09-21 16:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.