結果
| 問題 |
No.1731 Product of Subsequence
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-08 12:58:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,214 ms / 2,000 ms |
| コード長 | 1,877 bytes |
| コンパイル時間 | 3,182 ms |
| コンパイル使用メモリ | 78,696 KB |
| 実行使用メモリ | 61,000 KB |
| 最終ジャッジ日時 | 2024-11-08 05:08:55 |
| 合計ジャッジ時間 | 18,339 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = sc.nextInt();
HashMap<Integer, Integer> counts = new HashMap<>();
for (int i = 0; i < n; i++) {
int x = getGCD(sc.nextLong(), k);
HashMap<Integer, Integer> next = new HashMap<>();
for (int y : counts.keySet()) {
int z = getGCD((long)x * y, k);
next.put(z, (next.getOrDefault(z, 0) + counts.get(y)) % MOD);
}
for (int y : next.keySet()) {
counts.put(y, (counts.getOrDefault(y, 0) + next.get(y)) % MOD);
}
counts.put(x, (counts.getOrDefault(x, 0) + 1) % MOD);
}
System.out.println(counts.getOrDefault(k, 0));
}
static int getGCD(long x, long y) {
if (x % y == 0) {
return (int)y;
} else {
return getGCD(y, x % y);
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten