結果

問題 No.1243 約数加算
ユーザー tentententen
提出日時 2020-10-05 02:49:54
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,365 bytes
コンパイル時間 5,766 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 58,448 KB
最終ジャッジ日時 2023-09-27 01:19:17
合計ジャッジ時間 7,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,688 KB
testcase_01 AC 121 ms
55,416 KB
testcase_02 AC 122 ms
55,780 KB
testcase_03 AC 165 ms
56,608 KB
testcase_04 AC 298 ms
58,448 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		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<>();
	    while (a < b) {
	        if (a * 2 <= b) {
	            list.add(a);
	            a *= 2;
	            continue;
	        }
	        ArrayList<Long> tmp = new ArrayList<>();
	        for (long i = 2; i <= Math.sqrt(a) && a + i <= b; i++) {
	            if (a % i == 0) {
	                if (a + a / i <= b) {
	                    tmp.add(a / i);
	                    break;
	                } else {
	                    tmp.add(i);
	                }
	            }
	        }
	        if (tmp.size() == 0) {
	            list.add(1L);
	            a++;
	        } else {
	            list.add(tmp.get(tmp.size() - 1));
	            a += tmp.get(tmp.size() - 1);
	        }
	    }
	    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