結果

問題 No.1243 約数加算
ユーザー tentententen
提出日時 2020-10-05 03:05:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 2,867 ms
コンパイル使用メモリ 81,196 KB
実行使用メモリ 58,712 KB
最終ジャッジ日時 2023-09-27 01:19:44
合計ジャッジ時間 5,723 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,792 KB
testcase_01 AC 117 ms
56,240 KB
testcase_02 AC 117 ms
56,144 KB
testcase_03 AC 113 ms
54,080 KB
testcase_04 AC 146 ms
55,900 KB
testcase_05 AC 181 ms
56,096 KB
testcase_06 AC 177 ms
58,264 KB
testcase_07 AC 152 ms
55,748 KB
testcase_08 AC 169 ms
58,712 KB
testcase_09 AC 121 ms
55,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    static long[] base = new long[60];
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		base[0] = 1;
		for (int i = 1; i < base.length; i++) {
		    base[i] = base[i - 1] * 2;
		}
		int t = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < t; i++) {
		    sb.append(getString(sc.nextLong(), sc.nextLong())).append("\n");
		}
		System.out.print(sb);
	}
	
	static StringBuilder getString(long a, long b) {
	    ArrayList<Long> list = new ArrayList<>();
	    for (int i = 1; i < base.length; i++) {
	        if (a + base[i - 1] > b) {
	            break;
	        }
	        if (a % base[i] != 0) {
	            a += base[i - 1];
	            list.add(base[i - 1]);
	        }
	    }
	    for (int i = base.length - 1; i >= 0; i--) {
	        if (a + base[i] <= b) {
	            list.add(base[i]);
	            a += base[i];
	        }
	    }
	    StringBuilder sb = new StringBuilder();
	    sb.append(list.size()).append("\n");
	    for (int i = 0; i < list.size(); i++) {
	        if (i > 0) {
	            sb.append(" ");
	        }
	        sb.append(list.get(i));
	    }
	    return sb;
	}
}
0