結果

問題 No.1243 約数加算
ユーザー ttakezawattakezawa
提出日時 2020-10-02 23:47:50
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 11,083 ms
コンパイル使用メモリ 218,160 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 00:10:20
合計ジャッジ時間 12,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	defer writer.Flush()
	T := ReadInt()
	for t := 0; t < T; t++ {
		A, B := ReadInt(), ReadInt()
		solve(A, B)
	}
}

func solve(A, B int) {
	ans := make([]int, 0)
	N := 60

	var l int
	for i := N; i >= 0; i-- {
		if A>>i&1 == 0 && B>>i&1 == 1 {
			l = i
			break
		}
	}

	for i := 0; i < l; i++ {
		if A>>i&1 == 1 {
			A += 1 << i
			ans = append(ans, 1<<i)
		}
	}

	for i := l - 1; i >= 0; i-- {
		if A>>i&1 == 0 && B>>i&1 == 1 {
			ans = append(ans, 1<<i)
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		if i > 0 {
			Printf(" ")
		}
		Printf("%d", ans[i])
	}
	Println()
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }
0