結果

問題 No.639 An Ordinary Sequence
ユーザー Grenache
提出日時 2018-02-12 12:37:33
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 769 bytes
コンパイル時間 3,977 ms
コンパイル使用メモリ 78,384 KB
実行使用メモリ 54,696 KB
最終ジャッジ日時 2025-01-02 02:19:45
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder639 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		hm = new HashMap<>();
		hm.put(0L, 1L);

		pr.println(rec(n));
	}

	private static long rec(long n) {
		if (hm.containsKey(n)) {
			return hm.get(n);
		}

		long ret = rec(n / 3) + rec(n / 5);

		hm.put(n, ret);
		return ret;
	}

	private static Map<Long, Long> hm;

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0