結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kou6839kou6839
提出日時 2015-12-14 12:23:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,111 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 73,892 KB
実行使用メモリ 65,588 KB
最終ジャッジ日時 2023-10-13 16:27:36
合計ジャッジ時間 20,487 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,084 KB
testcase_01 AC 106 ms
56,380 KB
testcase_02 AC 109 ms
55,884 KB
testcase_03 AC 114 ms
55,536 KB
testcase_04 AC 111 ms
56,184 KB
testcase_05 AC 116 ms
55,968 KB
testcase_06 AC 113 ms
55,908 KB
testcase_07 AC 114 ms
56,036 KB
testcase_08 AC 114 ms
56,184 KB
testcase_09 WA -
testcase_10 AC 119 ms
55,784 KB
testcase_11 AC 116 ms
55,864 KB
testcase_12 AC 127 ms
55,920 KB
testcase_13 AC 121 ms
56,180 KB
testcase_14 AC 534 ms
61,924 KB
testcase_15 AC 637 ms
65,084 KB
testcase_16 AC 463 ms
60,724 KB
testcase_17 AC 160 ms
56,636 KB
testcase_18 WA -
testcase_19 AC 677 ms
62,668 KB
testcase_20 WA -
testcase_21 AC 508 ms
61,452 KB
testcase_22 AC 371 ms
60,792 KB
testcase_23 AC 612 ms
64,572 KB
testcase_24 WA -
testcase_25 AC 516 ms
62,688 KB
testcase_26 WA -
testcase_27 AC 633 ms
62,772 KB
testcase_28 WA -
testcase_29 AC 676 ms
65,588 KB
testcase_30 AC 183 ms
57,168 KB
testcase_31 WA -
testcase_32 AC 488 ms
60,344 KB
testcase_33 AC 478 ms
60,396 KB
testcase_34 WA -
testcase_35 AC 577 ms
64,836 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 339 ms
60,472 KB
testcase_40 WA -
testcase_41 AC 427 ms
60,628 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);
		}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