結果

問題 No.1243 約数加算
ユーザー ttakezawattakezawa
提出日時 2020-10-03 01:30:54
言語 Go
(1.22.1)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 11,066 ms
コンパイル使用メモリ 202,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 02:57:28
合計ジャッジ時間 11,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 < B>>i&1 {
			l = i
			break
		}
	}

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

	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 }

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