結果

問題 No.152 貯金箱の消失
ユーザー yukirinyukirin
提出日時 2016-03-03 23:31:18
言語 Go
(1.22.1)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 827 bytes
コンパイル時間 10,804 ms
コンパイル使用メモリ 227,192 KB
実行使用メモリ 50,924 KB
最終ジャッジ日時 2024-04-19 06:55:16
合計ジャッジ時間 11,756 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 15 ms
13,980 KB
testcase_08 AC 104 ms
50,664 KB
testcase_09 AC 127 ms
50,924 KB
testcase_10 AC 88 ms
37,760 KB
testcase_11 AC 39 ms
22,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	sc.Split(bufio.ScanWords)
	l := nextInt() / 4
	count := 0
	for _, v := range revEuclid(int(math.Sqrt(float64(l))), 1, 1) {
		a, b, c := v[0]*v[0]-v[1]*v[1], 2*v[0]*v[1], v[0]*v[0]+v[1]*v[1]
		if l >= a+b+c {
			count++
			count %= 1000003
		}
	}
	fmt.Println(count)
}

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

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

func revEuclid(n, a, b int) [][]int {
	ret := make([][]int, 0, 2000)

	var f func(int, int, int)
	f = func(m, c, d int) {
		for e := c + d; e <= m; e += d {
			if (e-d)%2 == 1 {
				ret = append(ret, []int{e, d})
			}
			f(n, d, e)
		}
	}
	f(n, a, b)
	return ret
}
0