結果

問題 No.1200 お菓子配り-3
ユーザー aru aruaru aru
提出日時 2020-12-08 21:56:07
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 2,200 bytes
コンパイル時間 11,984 ms
コンパイル使用メモリ 219,132 KB
実行使用メモリ 7,744 KB
最終ジャッジ日時 2023-10-18 23:57:20
合計ジャッジ時間 25,683 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 TLE -
testcase_03 AC 3,350 ms
4,348 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type pair struct {
	a, b int
}

func divisor(n int) []pair {
	ret := []pair{}
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			ret = append(ret, pair{i, n / i})
		}
	}
	return ret
}

func f(X, Y int) {
	ans := 0
	for b := 1; b < Y; b++ {
		v := X*X - 4*(b*Y-b*b)
		vi := int(math.Sqrt(float64(v)))
		if vi*vi != v {
			continue
		}
		C := []int{X + vi, X - vi}
		for _, c := range C {
			if c >= Y {
				continue
			}
			if c%2 != 0 {
				continue
			}
			c /= 2
			if c*X-b*Y == c*c-b*b {
				if (X-c)%b == 0 {
					// a := (X - c) / b
					// out(a, b, c)
					ans++
				}
			}
		}
	}
	out(ans)
}

func solve(x, y int) {
	cnt := 0
	for a := 1; a <= x; a++ {
		for b := 1; a*b < x; b++ {
			c := x - (a * b)
			if c == 0 {
				continue
			}
			if b == y-(a*c) {
				out(a, b, c)
				cnt++
			}
		}
	}
	out(cnt)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	s := getI()
	for i := 0; i < s; i++ {
		x, y := getI(), getI()
		f(x, y)
	}
}
0