結果
問題 |
No.1146 土偶Ⅰ
|
ユーザー |
|
提出日時 | 2020-08-05 19:32:41 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 2,048 ms |
コンパイル使用メモリ | 74,652 KB |
実行使用メモリ | 50,972 KB |
最終ジャッジ日時 | 2024-09-17 09:47:22 |
合計ジャッジ時間 | 3,802 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
import java.io.*; public class Main { static int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(br.readLine()); } int ans = 0; for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ int g = gcd(a[i], a[j]); if(g == 1){ ans += n-j-1; continue; } for(int k = j+1; k < n; k++){ ans += gcd(g, a[k])==1 ? 1 : 0; } } } System.out.println(ans); } }