結果
| 問題 |
No.917 Make One With GCD
|
| ユーザー |
htensai
|
| 提出日時 | 2019-12-10 11:56:32 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 933 bytes |
| コンパイル時間 | 2,424 ms |
| コンパイル使用メモリ | 79,484 KB |
| 実行使用メモリ | 62,124 KB |
| 最終ジャッジ日時 | 2024-06-24 00:21:08 |
| 合計ジャッジ時間 | 7,327 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 6 TLE * 1 -- * 25 |
ソースコード
import java.util.*;
public class Main {
static int n;
static int[] arr;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
System.out.println(search(0, -1));
}
static long search(int idx, int value) {
if (idx >= n) {
return 0;
}
long ans = search(idx + 1, value);
if (value == -1) {
value = arr[idx];
} else {
value = gcd(value, arr[idx]);
}
if (value == 1) {
ans += (long)(Math.pow(2, n - idx - 1));
} else {
ans += search(idx + 1, value);
}
return ans;
}
static int gcd(int x, int y) {
if (x % y == 0) {
return y;
} else {
return gcd(y, x % y);
}
}
}
htensai