Big loop inside of others

0
The challenge is to find x different ways of dividing the object, for 3 people in which each has to receive a value less than or equal to M, and the sum of the value that each one has had to be equal to N, Here is the code I did:

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 took SO MUCH time to give the result, there is some way, to simplify it, some theorem, or something, something that would make it go faster. Thanks

    
asked by anonymous 15.04.2016 / 22:40

0 answers