結果

問題 No.639 An Ordinary Sequence
ユーザー htensaihtensai
提出日時 2019-11-14 08:46:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 481 bytes
コンパイル時間 4,753 ms
コンパイル使用メモリ 72,272 KB
実行使用メモリ 56,156 KB
最終ジャッジ日時 2023-08-30 13:10:01
合計ジャッジ時間 5,824 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,964 KB
testcase_01 AC 128 ms
55,736 KB
testcase_02 AC 124 ms
55,828 KB
testcase_03 AC 123 ms
55,860 KB
testcase_04 AC 125 ms
55,744 KB
testcase_05 AC 125 ms
55,840 KB
testcase_06 AC 124 ms
55,848 KB
testcase_07 AC 126 ms
56,088 KB
testcase_08 AC 120 ms
55,724 KB
testcase_09 AC 124 ms
55,868 KB
testcase_10 AC 121 ms
55,916 KB
testcase_11 AC 121 ms
55,552 KB
testcase_12 AC 127 ms
55,980 KB
testcase_13 AC 127 ms
56,092 KB
testcase_14 AC 124 ms
56,156 KB
testcase_15 AC 125 ms
55,876 KB
testcase_16 AC 125 ms
55,852 KB
testcase_17 AC 124 ms
56,004 KB
testcase_18 AC 126 ms
55,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static HashMap<Long, Long> map = new HashMap<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		System.out.println(getValue(n));
	}
	
	static long getValue(long x) {
	    if (x == 0) {
	        return 1;
	    }
	    if (map.containsKey(x)) {
	        return map.get(x);
	    }
	    long ans = getValue(x / 3) + getValue(x / 5);
	    map.put(x, ans);
	    return ans;
	}
}
0