結果

問題 No.1791 Repeat Multiplication
ユーザー ripity
提出日時 2021-11-21 15:41:08
言語 Java
(openjdk 23)
結果
AC  
実行時間 761 ms / 3,000 ms
コード長 613 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 79,656 KB
最終ジャッジ日時 2024-09-15 14:52:58
合計ジャッジ時間 23,490 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		long[] dp = new long[N+1];
		long[] sum = new long[N+1];
		dp[1] = 1;
		for( int i = 1; i <= N; i++ ) {
			sum[i] = dp[i]+sum[i-1];
			for( int j = 2; i*j <= N; j++ ) {
				dp[i*j] += dp[i];
			}
		}
		
		for( int i = 0; i < Q; i++ ) {
		    int x = Integer.parseInt(sc.next());
			pw.println(dp[x]*sum[N/x]);
		}
		
		sc.close();
		pw.flush();
		
	}
	
}
0