← Home
For problem statement at 1000-1999/1800-1899/1870-1879/1872/problemD.txt this is a correct solution, but verifier at 1000-1999/1800-1899/1870-1879/1872/verifierD.go ends with All tests passed can you fix the verifier? package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	if !scanner.Scan() {
		return
	}

	tStr := scanner.Text()
	t, _ := strconv.Atoi(tStr)

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		y, _ := strconv.ParseInt(scanner.Text(), 10, 64)

		g := gcd(x, y)
		lcmPart := x / g
		var kxy int64
		if lcmPart <= n/y {
			kxy = n / (lcmPart * y)
		} else {
			kxy = 0
		}

		cx := (n / x) - kxy
		cy := (n / y) - kxy

		sumX := cx * (2*n - cx + 1) / 2
		sumY := cy * (cy + 1) / 2

		fmt.Fprintln(out, sumX-sumY)
	}
}