Performs (a^x) modulo N, for given integers a and N. The x (one value or a superposition) is given in the input register x.

After computation, the result (or results, when x stores superposition of multiple integers) is stored in register x1.

This method is a variant of ExpModulo function, which operates directly on quantum registers given as arguments. It neither allocates nor frees any additional registers. It is thus recommended, when there is a need for performing modular exponentiation repeatedly. However, this variant has strict requirements for the width of each given register and if they are not fullfilled, the method gives unexpected results.

**Namespace:**Quantum.Operations

**Assembly:**Quantum (in Quantum.dll) Version: 1.0.0.0 (1.0.0.0)

#### Parameters

- comp
- Type: Quantum QuantumComputer

The QuantumComputer instance.

- a
- Type: Quantum Register

Accumulator register. Its initial value must be 0. Its width must equal**WIDTH**(See Remarks).

- b
- Type: Quantum Register

Helper register. Its initial value must be 0. Its width must equal**WIDTH + 1**(See Remarks).

- c
- Type: Quantum Register

Register for storing carry bits. Its initial value must be 0. Its width must equal**WIDTH + 1**(See Remarks).

- N
- Type: Quantum Register

Register for N. Its initial value must equal N. Its width must equal**WIDTH**(See Remarks).

- x1
- Type: Quantum Register

Output register. Its initial value must equal 1. Its width must equal**WIDTH + 1**(See Remarks).

- x
- Type: Quantum Register

Register for x. Its initial value could be any integer or a superposition of multiple integers. Its width must equal**2 * WIDTH**(See Remarks).

- valueA
- Type: System Int32

Integer value of a. (For computing (a^x) modulo N).

- valueN
- Type: System Int32

Integer value of N. (For computing (a^x) modulo N).

#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type QuantumComputer. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).There are precise requirements for the width of each register given as argument. They result from a need for carry bits, overflow flag and a requirement for ensuring that the operation is inversible.

Let **WIDTH** equals the number of bits required to store N.

The width of x register must equal **2 * WIDTH**. This value results from the requirements of Peter Shor's
algorithm. Such a width ensures that the probability of getting the right result will be enough high.