# agent402.tools Modular Arithmetic

> agent402.tools Modular Arithmetic is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-14).

Performs modular arithmetic operations (mod, modpow, modinverse) using arbitrary-precision BigInt arithmetic for cryptography and number theory applications.

## Facts

- Endpoint: POST https://agent402.tools/api/mod-arithmetic
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agent402-tools-modular-arithmetic-bf12def3
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ooM9NxGpu5hk3Lzm9xAt2

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability agent402-tools-modular-arithmetic-bf12def3 -d '<json body>'
```

Example prompt: Can you compute 2 to the power of 100 mod 1000000007 using fast modular exponentiation (modpow), with a=2, b=100, and m=1000000007?

## When to prefer this

Use this endpoint when you need arbitrary-precision modular arithmetic, especially for cryptographic protocols (RSA, Diffie-Hellman), primality testing, or number theory calculations where standard integer overflow would be a problem. Prefer over general-purpose math libraries when you need a hosted, pay-per-call API with BigInt support.

## Known failure modes

- Modulus m <= 0 results in an error (modulus must be positive)
- modinverse fails if no modular inverse exists (when gcd(a, m) != 1)
- Missing required parameter 'b' for modpow operation
- Invalid 'op' string (must be 'mod', 'modpow', or 'modinverse')
- Non-integer inputs cause validation failure

## How this service works

Modular arithmetic operations: mod (a mod m), modpow (a^b mod m via fast exponentiation), and modinverse (a^-1 mod m via extended Euclidean algorithm). Uses BigInt for arbitrary precision. Useful for cryptography and number theory.

## Output

A numeric result corresponding to the requested modular arithmetic operation: a mod m for 'mod', a^b mod m for 'modpow', or the modular inverse a^-1 mod m for 'modinverse', all computed using arbitrary-precision BigInt arithmetic.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "a": {
   "type": "integer",
   "description": "base value"
  },
  "b": {
   "type": "integer",
   "description": "exponent (required for modpow)"
  },
  "m": {
   "type": "integer",
   "description": "modulus (must be > 0)"
  },
  "op": {
   "type": "string",
   "description": "\"mod\", \"modpow\", or \"modinverse\""
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "a": "7",
  "b": "256",
  "m": "13",
  "op": "modpow",
  "result": "9"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agent402-tools-modular-arithmetic-bf12def3/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
