結果

問題 No.593 4進FizzBuzz
ユーザー tookunn_1213tookunn_1213
提出日時 2017-11-10 23:28:40
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 10,273 ms
コンパイル使用メモリ 233,736 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2024-05-03 14:40:13
合計ジャッジ時間 11,778 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

type Scanner struct {

    reader *bufio.Reader
    buffer []string
    pointer int
}

func NewScanner() *Scanner {
    return &Scanner{
        reader: bufio.NewReaderSize(os.Stdin,4096),
        pointer: 0,
    }
}

func (self *Scanner) NextLine () string {
    var buffer []byte
    for {
        line,isPrefix,_ := self.reader.ReadLine()
        buffer = append(buffer, line...)
        if !isPrefix {
            break
        }
    }
    return string(buffer)
}

func (self *Scanner) Next () string {
    if self.pointer >= len(self.buffer) {
        line := self.NextLine()
        self.buffer = strings.Fields(line)
        self.pointer = 0
    }
    self.pointer++
    return self.buffer[self.pointer-1]
}

func (self *Scanner) NextInt () int {
    s := self.Next()
    i,_ := strconv.ParseInt(s,10,32)
    return int(i)
}

func (self *Scanner) NextLong () int64{
    s := self.Next()
    l,_ := strconv.ParseInt(s,10,64)
    return int64(l)
}

func (self *Scanner) NextFloat () float32 {
    s := self.Next()
    f,_ := strconv.ParseFloat(s,32)
    return float32(f)
}

func (self *Scanner) NextDouble () float64 {
    s := self.Next()
    d,_ := strconv.ParseFloat(s,64)
    return float64(d)
}

func modpow(x,y,mod int64) int64 {
	if y == 0 {
		return int64(1)
	}
	if y % 2 == 1 {
		return modpow(x,y-1,mod) * x % mod
	}
	tmp := modpow(x,y/2,mod)
	return tmp * tmp % mod
}

func main () {
    cin := NewScanner()

	N := cin.NextLong()
	tmpN := N
	
	modThree := int64(0)
	modFive := int64(0)
	cnt := int64(0)

	for N > 0 {
		modThree += N % 10 * modpow(4,cnt,3)
		modThree %= 3
		modFive += N % 10 * modpow(4,cnt,5)
		modFive %= 5
		N /= 10
		cnt++
	}

	if modThree == 0 && modFive == 0 {
		fmt.Println("FizzBuzz")
	} else if modFive == 0 {
		fmt.Println("Buzz")
	} else if modThree == 0 {
		fmt.Println("Fizz")
	} else {
		fmt.Println(tmpN)
	}
}
0