結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kou6839kou6839
提出日時 2015-12-14 12:29:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,274 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 74,688 KB
実行使用メモリ 66,688 KB
最終ジャッジ日時 2023-10-13 16:28:40
合計ジャッジ時間 20,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
55,800 KB
testcase_01 AC 106 ms
55,792 KB
testcase_02 AC 110 ms
56,036 KB
testcase_03 AC 109 ms
56,284 KB
testcase_04 AC 109 ms
55,744 KB
testcase_05 AC 119 ms
56,184 KB
testcase_06 AC 114 ms
56,144 KB
testcase_07 AC 115 ms
56,060 KB
testcase_08 AC 112 ms
55,924 KB
testcase_09 WA -
testcase_10 AC 112 ms
55,892 KB
testcase_11 AC 117 ms
56,176 KB
testcase_12 AC 120 ms
55,904 KB
testcase_13 AC 124 ms
56,020 KB
testcase_14 AC 502 ms
63,816 KB
testcase_15 AC 656 ms
64,664 KB
testcase_16 AC 480 ms
60,332 KB
testcase_17 AC 169 ms
56,384 KB
testcase_18 WA -
testcase_19 AC 553 ms
63,464 KB
testcase_20 WA -
testcase_21 AC 517 ms
63,472 KB
testcase_22 AC 369 ms
62,632 KB
testcase_23 AC 605 ms
64,796 KB
testcase_24 WA -
testcase_25 AC 517 ms
61,416 KB
testcase_26 WA -
testcase_27 AC 583 ms
63,108 KB
testcase_28 WA -
testcase_29 AC 649 ms
65,160 KB
testcase_30 AC 198 ms
58,868 KB
testcase_31 WA -
testcase_32 AC 511 ms
62,720 KB
testcase_33 AC 498 ms
60,324 KB
testcase_34 WA -
testcase_35 AC 606 ms
63,824 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 337 ms
60,568 KB
testcase_40 WA -
testcase_41 AC 447 ms
60,508 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 && (p%2==0 || q%2==0)){
			System.out.println(n);
			return;
		}else if(gcd(p, q)==1){
			int ans = 0;
			for(int i=0;i<n;i++){
				if( Math.abs(x[i]+y[i])%2==0) ans++;
			}
			System.out.println(ans);
			return;
		}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( (x[i]%sa==0 || y[i]%sa==0) && Math.abs(x[i]-y[i])%(sa*2)==0) ans++;
			}
			System.out.println(ans);
		}
	} 
}
0