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.
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)
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"
}
}
}
}
Pass all numbers as parameters to the gcd tool. It processes them sequentially, finding GCD(a,b) first, then GCD(result,c), etc.
GCD(a,0) returns |a|, and negative numbers are treated as their absolute values. GCD(-12, 8) returns 4.
Yes, divide both numerator and denominator by their GCD. For fraction 12/18, GCD(12,18)=6, so simplified form is 2/3.
GCD finds the largest common divisor, while LCM finds the smallest common multiple. They're related: LCM(a,b) = (a×b)/GCD(a,b).
Yes, it uses the Euclidean algorithm which runs in O(log min(a,b)) time, making it efficient even for very large numbers.