← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, x, y int64
		fmt.Fscan(in, &n, &x, &y)

		g := gcd(x, y)
		l := x / g * y

		common := n / l
		pos := n/x - common
		neg := n/y - common

		sumLarge := pos * (2*n - pos + 1) / 2
		sumSmall := neg * (neg + 1) / 2

		fmt.Fprintln(out, sumLarge-sumSmall)
	}
}
```