Large Inside Loop of Other

Asked

Viewed 38 times

0

The challenge is to find x different ways to divide the object, for 3 people where each has to receive a value less than or equal to M, and the sum of the value that each won has to be equal to N, follows below the code that I made:

int m,n;
m = 98765;
n = 100000;

for (int i = m; i > 0; i--)
            {
                for (int j = m; j > 0; j--)
                {
                    for (int b = m; b > 0; b--)
                    {
                        Console.WriteLine(i + "   " + j + "    " + b);
                        if (i + j + b == n)
                        {
                            Console.WriteLine(somas++);
                           /* As linhas abaixo são para observar como decorre o programa */
                            Console.WriteLine(i + "   " + j + "    " + b);//
                        }
                    }

                }

            }

however, for the specified values of N and M, the project will take TOO long to give the result, there is some way, to simplify this, some theorem, or something like that, something that would make it go faster. Thank you

  • I took this test here and I think it’s printing wrong. Or I didn’t understand what goes on i, j and b.

  • i, j and b, are the numbers of the division of objects between the 3 persons, let’s assume that the division for each student has to be smaller q 34 and the sum of the amount of each object that each person has will be 100: 34 + 34 + 32 = 100, ie i + j + b = 100, these variables are used to check if the

  • link from where I took the challenge, I think this might help you understand the context

  • Can you put the right answer to the question? In a hasty mathematics I got 2,287,837.

  • Yes, but then, you saw that in the example I put up beginning printing 98, 98 and 98?

  • @Brunocosta, for the values cited is: 4997567718

  • @Ciganomorrisonmendez, for some reason, I think the site changed the value from 98765 to 98 and from 100000 to 100, why it is generating such values

  • I changed because the output was too big. It was not the site. The problem is not this. The algorithm, and therefore the answer, are wrong.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.