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 9248897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:03:37+00:00 2026-06-18T10:03:37+00:00

I was working on a coding problem and as subpart of it I got

  • 0

I was working on a coding problem and as subpart of it I got this problem:

We are given a number x and we square it so number becomes x^2. Now we have numbers from 1 to x^2 e.g:
if number=4;
then
4^2=16

         1             ----->1
      2     3          ----->2
   4     5     6       ----->3
7     8     9    10    ----->4
  11    12    13       ----->5
     14    15          ----->6
        16             ----->7

Now I am given a number say k and I need to tell that to which group it belongs. Here 8 belongs to 4th group.

What I thought is start from 1 and keep count initialized to 1 and check whether 1<8? if yes then add 2 to 1(prev sum),increase count to 2 and check whether 3<8? if yes then add 3 to 3(prev sum),increase count to 3 and check whether 6<8 if yes then add 4 to 6, increase count to 4 and check whether 10<9? if no then exit.
So group no. is count i.e 4.

But is there any fast method than my approach?

EDIT 1:
I forgot to mention that in my algo when count reaches the given number which is 4 in prev example then I should not add 5 but 3. e.g.:

If number to search is 14 then

1<14 yes then add 2

3<14 yes then add 3

6<14 yes then add 4

10<14 yes then add **3**  ---->here I need to add 3 instead of 5

13<14 yes then add **2**  ---->here I need to add 2 instead of 6

15<14 No so output count.

it is possible to add 3 instead of 5 using if condition but is there any method in which the value to be added automatically increases and then decreases depending on value of x(see example above to know what x refers to)

  • 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-18T10:03:38+00:00Added an answer on June 18, 2026 at 10:03 am

    The upper half of the rectangle is a triangle:

             1             ----->1
          2     3          ----->2
       4     5     6       ----->3
    7     8     9    10    ----->4
    

    and the numbers on the right side (1, 3, 6, 10) are called triangular numbers. The inverse formula there (under the subtitle “Triangular roots and tests for triangular numbers”) can be used for your problem:

    def group(x, number):
        if number <= x^2 / 2 :
            return ceiling( (sqrt(8*number+1) - 1) / 2 )
        else:
            return 2*x - group(x, x^2+1-number)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is one of the problem i have been working from a long time.This
Recently I have been working with the xml coding,and the problem happened. Given the
I have a problem in my coding which was working fine with an older
Now this is a weird problem. I was coding two days ago and stopped
I have been working on a coding problem for some pages I inherited where
I am working on coding a GUI with C#. I'm following this simple tutorial
I am working on some form coding in PHP, and I have everything working
I am working on a coding problem and I need to check whether a
I've been working on this problem for a stupid amount of time. It is
All, I have been practicing coding problems online. Currently I am working on 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.