Math Utilities

Gcd

Calculate the greatest common divisor (GCD) of two or more integers using the Euclidean algorithm. Access via MCP in Cursor or Windsurf for mathematical computations, or call GET /v1/math/gcd with number parameters. Returns the largest positive integer that divides all input numbers without remainder. Handles negative numbers and zero correctly.

API Endpoint

GET /v1/math/gcd

Code Examples

curl "https://tinyfn.io/v1/math/gcd" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/gcd', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/math/gcd',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's math tools:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://tinyfn.io/mcp/math",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I calculate GCD of multiple numbers using MCP?

Pass all numbers as parameters to the gcd tool. It processes them sequentially, finding GCD(a,b) first, then GCD(result,c), etc.

What happens when I calculate GCD with zero or negative numbers?

GCD(a,0) returns |a|, and negative numbers are treated as their absolute values. GCD(-12, 8) returns 4.

Can I use GCD for simplifying fractions in my code?

Yes, divide both numerator and denominator by their GCD. For fraction 12/18, GCD(12,18)=6, so simplified form is 2/3.

What's the difference between GCD and LCM calculations?

GCD finds the largest common divisor, while LCM finds the smallest common multiple. They're related: LCM(a,b) = (a×b)/GCD(a,b).

Does the GCD function handle large integers efficiently?

Yes, it uses the Euclidean algorithm which runs in O(log min(a,b)) time, making it efficient even for very large numbers.

Try Gcd Now

Get your free API key and start using Gcd in seconds.

Get Free API Key