結果
問題 |
No.321 (P,Q)-サンタと街の子供たち
|
ユーザー |
![]() |
提出日時 | 2015-12-14 12:09:09 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,059 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 77,352 KB |
実行使用メモリ | 58,168 KB |
最終ジャッジ日時 | 2024-09-15 12:25:34 |
合計ジャッジ時間 | 24,801 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 14 WA * 27 |
ソースコード
import java.util.*; public class Main { static long gcd(long a,long b){ return b == 0 ? a : gcd(b, a%b); } static long lcm(long a, long b){ return a*b/gcd(a, b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); long p = sc.nextLong(); long q = sc.nextLong(); int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i=0;i<n;i++){ x[i] = sc.nextInt(); y[i] = sc.nextInt(); } if(gcd(p, q)==1){ System.out.println(n); }else if(p==0&&q==0){ int ans = 0; for(int i=0;i<n;i++){ if( x[i]==0&&y[i]==0) ans++; } System.out.println(ans); }else if(p==0){ int ans = 0; for(int i=0;i<n;i++){ if( y[i]%q==0 && x[i]%q==0) ans++; } System.out.println(ans); }else if(q==0){ int ans = 0; for(int i=0;i<n;i++){ if( y[i]%p==0 && x[i]%p==0) ans++; } System.out.println(ans); }else{ int ans =0; long sa = gcd(p, q); for(int i=0;i<n;i++){ if( Math.abs(x[i]-y[i])%(sa*2)==0) ans++; } System.out.println(ans); } } }