d01gz calculates the optimal coefficients for use by (D01GCF not in this release) d01gd, when the number of points is the product of two primes.

# Syntax

C#
```public static void d01gz(
int ndim,
int np1,
int np2,
double[] vk,
out int ifail
)```
Visual Basic
```Public Shared Sub d01gz ( _
ndim As Integer, _
np1 As Integer, _
np2 As Integer, _
vk As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void d01gz(
int ndim,
int np1,
int np2,
array<double>^ vk,
[OutAttribute] int% ifail
)```
F#
```static member d01gz :
ndim : int *
np1 : int *
np2 : int *
vk : float[] *
ifail : int byref -> unit
```

#### Parameters

ndim
Type: System..::..Int32
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 1$.
np1
Type: System..::..Int32
On entry: the larger prime factor ${p}_{1}$ of the number of points in the integration rule.
Constraint: ${\mathbf{np1}}$ must be a prime number $\text{}\ge 5$.
np2
Type: System..::..Int32
On entry: the smaller prime factor ${p}_{2}$ of the number of points in the integration rule. For maximum efficiency, ${p}_{2}^{2}$ should be close to ${p}_{1}$.
Constraint: ${\mathbf{np2}}$ must be a prime number such that ${\mathbf{np1}}>{\mathbf{np2}}\ge 2$.
vk
Type: array<System..::..Double>[]()[][]
An array of size [ndim]
On exit: the $n$ optimal coefficients.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

Korobov (1963) gives a procedure for calculating optimal coefficients for $p$-point integration over the $n$-cube ${\left[0,1\right]}^{n}$, when the number of points is
 $p=p1p2$ (1)
where ${p}_{1}$ and ${p}_{2}$ are distinct prime numbers.
The advantage of this procedure is that if ${p}_{1}$ is chosen to be the nearest prime integer to ${p}_{2}^{2}$, then the number of elementary operations required to compute the rule is of the order of ${p}^{4/3}$ which grows less rapidly than the number of operations required by d01gy. The associated error is likely to be larger although it may be the only practical alternative for high values of $p$.

# References

Korobov N M (1963) Number Theoretic Methods in Approximate Analysis Fizmatgiz, Moscow

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ndim}}<1$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{np1}}<5$, or ${\mathbf{np2}}<2$, or ${\mathbf{np1}}\le {\mathbf{np2}}$.
${\mathbf{ifail}}=3$
The value ${\mathbf{np1}}×{\mathbf{np2}}$ exceeds the largest integer representable on the machine, and hence the optimal coefficients could not be used in a valid call of (D01GCF not in this release) d01gd.
${\mathbf{ifail}}=4$
 On entry, np1 is not a prime number.
${\mathbf{ifail}}=5$
 On entry, np2 is not a prime number.
${\mathbf{ifail}}=6$
The precision of the machine is insufficient to perform the computation exactly. Try smaller values of np1 or np2, or use an implementation with higher precision.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The optimal coefficients are returned as exact integers (though stored in a real array).

None.

# Further Comments

The time taken by d01gz grows at least as fast as ${\left({p}_{1}{p}_{2}\right)}^{4/3}$. (See [Description].)

# Example

This example calculates the Korobov optimal coefficients where the number of dimensons is $4$ and the number of points is the product of the two prime numbers, $89$ and $11$.

Example program (C#): d01gze.cs

Example program results: d01gze.r