結果
問題 | No.2811 Calculation Within Sequence |
ユーザー | ks2m |
提出日時 | 2024-07-19 21:26:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 533 ms / 2,000 ms |
コード長 | 889 bytes |
コンパイル時間 | 2,938 ms |
コンパイル使用メモリ | 75,868 KB |
実行使用メモリ | 65,632 KB |
最終ジャッジ日時 | 2024-07-19 21:26:53 |
合計ジャッジ時間 | 22,066 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]); int b = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); int[] t = new int[a]; for (int i = 0; i < a; i++) { t[i] = Integer.parseInt(sa[i]); } sa = br.readLine().split(" "); int[] s = new int[b]; for (int i = 0; i < b; i++) { s[i] = Integer.parseInt(sa[i]); } br.close(); int g = 0; for (int i = 0; i < a; i++) { g = gcd(g, t[i]); } for (int i = 0; i < b; i++) { if (s[i] % g != 0) { System.out.println("No"); return; } } System.out.println("Yes"); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } }