Solving a multi variable polynomial For this equation, I need to count possible solutions:

$$ a + b^2 + c^3 + d^4 \le S  $$

$$0\le a,b,c,d \le S$$

I tried the following approach:

       Integer S=Integer.parseInt(br.readLine());
      // get maximum possible value of a,b,c,d which satisfy equation
         int a=S;
        int b=(int) Math.sqrt(a);
        int d=(int) Math.sqrt(b);
        int c=(int) Math.cbrt(a);
        int count=0;
        for (int i = 0; i &lt;= a; i++) {
            for (int j = 0; j &lt;= b; j++) {
                for (int k = 0; k &lt;= c; k++) {
                    for (int l = 0; l &lt;= d; l++) {
                       int total=i+j*j+(int)Math.pow(k, 3)+ 
  (int)Math.pow(l,4);
                        if(total&lt;=a) {
                            count++;
                        }
                    }
                }
            }
        }
          System.out.println(count);


Time complexity: \$O(n \times \sqrt{n} \times \sqrt[3]{n} \times \sqrt[4]{n})\$ (Not sure) 

For large value, this takes time. Can someone please help me with better solution with time complexity?
a + b^2 + c^3 + d^4 &lt;= S
  For above equation ,I need to count possible solutions.
  
  I tried following approach.

Integer inp=Integer.parseInt(br.readLine());
      // get maximum possible value of b,c,d which satisfy equation
      int b=(int) Math.sqrt(inp);
        int d=(int) Math.sqrt(b);
        int c=(int) Math.cbrt(inp);
        int count=0;

  
  ...


If I were the interviewer, I would already have marked you down heavily for your choice of variable names. The problem statement defines a, b, c, d, S. The natural choice of variable names for those values are a, b, c, d, S. Using b, c, d for something else almost looks as though you were deliberately trying to make the code unmaintainable.



                        if(total&lt;=inp) {
                            count++;
                        }


Enumerating items one by one is nearly always the wrong way to count something.

If I asked you to count solutions to \$a \le S\$ would you write a loop? I hope not, because you can do it without any loop or any mathematical operations.

Now, how about \$a + b^2 \le S\$? This can be done with one mathematical expression. Hint: start from $$\sum_{b=0}^{\sqrt{S}} \textrm{countA}(S - b^2)$$

Cubes already grow quite fast, so

for (int c = 0; c &lt;= maxC; c++) {
    for (int d = 0; d &lt;= maxD; d++) {
        count += countAB(S - c*c*c - d*d*d*d)
    }
}


would be reasonably efficient. If you really want to microoptimise you can eliminate the multiplications in favour of some accumulators and addition, but that's probably not necessary for an interview question. They might ask about it in a follow-up.