D - 2-variable Function Editorial by psz2007


Let \(M=\sqrt[3]{N_{\max}}=\sqrt[3]{10^{18}}=10^6\). So we have \(a_{\max}\le\sqrt[3]{N}\le M\).

So we can just enumerate \(a\) from \(0\) to \(M\), and then binary search the smallest \(b\) such that \(X=a^3+a^2b+ab^2+b^3\ge N\). Time complexity is \(O(M\log M)\), easily pass the problem.

(Although time complexity is a bit worse than Official Editorial, but I think it’s a more straightford way.)

Sample Code(C++)

posted:
last update: