結果

問題 No.917 Make One With GCD
コンテスト
ユーザー htensai
提出日時 2019-12-10 11:56:32
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
TLE  
実行時間 -
コード長 933 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,001 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 93,932 KB
最終ジャッジ日時 2026-03-09 07:32:26
合計ジャッジ時間 17,374 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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);
       }
   }
}
0