$\newcommand{\+}{^{\daga}}
\newcommand{\ángulos}[1]{\left\langle\, nº 1 \,\right\rangle}
\newcommand{\llaves}[1]{\left\lbrace\, nº 1 \,\right\rbrace}
\newcommand{\bracks}[1]{\left\lbrack\, nº 1 \,\right\rbrack}
\newcommand{\ceil}[1]{\,\left\lceil\, nº 1 \,\right\rceil\,}
\newcommand{\dd}{{\rm d}}
\newcommand{\down}{\downarrow}
\newcommand{\ds}[1]{\displaystyle{#1}}
\newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
\newcommand{\fermi}{\,{\rm f}}
\newcommand{\piso}[1]{\,\left\lfloor #1 \right\rfloor\,}
\newcommand{\mitad}{{1 \over 2}}
\newcommand{\ic}{{\rm i}}
\newcommand{\iff}{\Longleftrightarrow}
\newcommand{\imp}{\Longrightarrow}
\newcommand{\isdiv}{\,\left.\a la derecha\vert\,}
\newcommand{\cy}[1]{\left\vert #1\right\rangle}
\newcommand{\ol}[1]{\overline{#1}}
\newcommand{\pars}[1]{\left (\, nº 1 \,\right)}
\newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\parcial #3^{#1}}}
\newcommand{\pp}{{\cal P}}
\newcommand{\raíz}[2][]{\,\sqrt[#1]{\vphantom{\large Un}\,#2\,}\,}
\newcommand{\sech}{\,{\rm sech}}
\newcommand{\sgn}{\,{\rm sgn}}
\newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
\newcommand{\ul}[1]{\underline{#1}}
\newcommand{\verts}[1]{\left\vert\, nº 1 \,\right\vert}
\newcommand{\wt}[1]{\widetilde{#1}}$
Con
$\ds{\pars{~\mbox{spherical coordinates}~}\ r = \root{x^{2} + y^{2} + z^{2}}}$, tenemos
$\ds{\nabla\cdot\pars{r\,\vec{r}} = {\vec{r} \over r}\cdot\vec{r} + 3r = 4r}$:
\begin{align}&\color{#c00000}{\int_{0}^{4}\int_{0}^{4}\int_{0}^{4}%
\root{x^{2} + y^{2} + z^{2}}\,\dd x\,\dd y\,\dd z}
=\int_{\bracks{0,4}^{3}}r\,\dd^{3}\vec{r}
=\int_{\bracks{0,4}^{3}}{1 \over 4}\,\nabla\cdot\pars{r\,\vec{r}}\,\dd^{3}\vec{r}
\\[3mm]&={1 \over 4}\int_{\rm S}r\,\vec{r}\cdot\dd\vec{\rm S}
={1 \over 4}\int_{\braces{0,4}^{2}}\root{16 + y^{2} + z^{2}}\,4\,\dd y\,\dd z
\\[3mm]&+{1 \over 4}\int_{\braces{0,4}^{2}}\root{x^{2} + 16 + z^{2}}\,4
\,\dd x\,\dd z
+{1 \over 4}\int_{\braces{0,4}^{2}}\root{x^{2} + y^{2} + 16}\,4\,\dd x\,\dd y
\end{align}
\begin{align}&\color{#66f}{\large\int_{0}^{4}\int_{0}^{4}\int_{0}^{4}%
\root{x^{2} + y^{2} + z^{2}}\,\dd x\,\dd y\,\dd z}
=3\int_{\braces{0,4}^{2}}\root{x^{2} + y^{2} + 16}\,\dd x\,\dd y
\\[3mm]&=3\int_{0}^{4}\int_{0}^{4}\root{x^{2} + y^{2} + 16}\,\dd y\,\dd x
=192\int_{0}^{1}\int_{0}^{1}\root{x^{2} + y^{2} + 1}\,\dd y\,\dd x
\\[3mm]&=48\int_{0}^{1}\left\{2\left[\root{x^{2} + 2} + \left(x^{2} + 1\right)
\ln\left(\root{x^{2} + 2} + 1\right)\right] - \left(x^{2} + 1\right)
\ln\left(x^{2} + 1\right)\right\}\,\dd x
\\[3mm]&=\color{#66f}{\large%
64\left[\root{3} + \ln\left(7 + 4\root{3}\right)\right] - {32\pi \over3}}
\approx {\tt 245.9115409}
\end{align}
// monteCarlo0.cc
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
typedef long double ldouble;
typedef unsigned long long ullong;
const ldouble RANDMAX1=ldouble(RAND_MAX) + 1.0 L;
const ullong ITER=100000000ULL; // cien millones de
ldouble X,Y;
en línea ldouble f(ldouble x,ldouble y)
{
return sqrt(x*x + y*y + 1.0 L);
}
en línea ldouble f()
{
X=rand()/RANDMAX1;
Y=rand()/RANDMAX1;
retorno (f(X,Y) + f(X,1.0 L - Y) + f(1,0 L - X,Y) + f(1,0 L - X,1.0 L - Y))/4.0 L;
}
int main()
{
ldouble suma=0;
para ( ullong n=0 ; n<ITER ; ++n ) suma+=f();
cout<<setprecision(50)<<(192.0 L*(suma/ITER))<<endl;
return 0;
}
Se ejecuta durante 7 segundos.
Resultado: $\ds{\color{#c00000}{\large 245.911}07650843407733676215798368502873927354812622}$.