結果
問題 | No.2609 Decreasing GCDs |
ユーザー | ks2m |
提出日時 | 2024-01-19 22:03:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 133 ms / 1,000 ms |
コード長 | 701 bytes |
コンパイル時間 | 3,375 ms |
コンパイル使用メモリ | 75,064 KB |
実行使用メモリ | 41,660 KB |
最終ジャッジ日時 | 2024-09-28 04:29:02 |
合計ジャッジ時間 | 6,529 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int[] a = new int[n]; a[0] = 1; for (int i = 1; i < n; i++) { a[i] = a[i - 1] * 2; } for (int i = n - 2; i >= 0; i--) { a[i] += a[i + 1]; } StringBuilder sb = new StringBuilder(); for (int i = n - 1; i >= 0; i--) { sb.append(a[i]).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); // for (int i = n - 2; i >= 0; i--) { // System.out.println(gcd(a[i + 1], a[i])); // } } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } }