結果

問題 No.1200 お菓子配り-3
ユーザー marroncastlemarroncastle
提出日時 2020-08-29 20:21:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,916 ms / 4,000 ms
コード長 985 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-05-01 00:16:25
合計ジャッジ時間 21,013 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,352 KB
testcase_01 AC 37 ms
58,112 KB
testcase_02 AC 36 ms
57,600 KB
testcase_03 AC 38 ms
57,600 KB
testcase_04 AC 38 ms
57,472 KB
testcase_05 AC 37 ms
57,472 KB
testcase_06 AC 37 ms
58,112 KB
testcase_07 AC 55 ms
59,136 KB
testcase_08 AC 52 ms
58,976 KB
testcase_09 AC 50 ms
59,008 KB
testcase_10 AC 50 ms
58,752 KB
testcase_11 AC 50 ms
58,880 KB
testcase_12 AC 183 ms
70,144 KB
testcase_13 AC 186 ms
71,808 KB
testcase_14 AC 184 ms
70,400 KB
testcase_15 AC 190 ms
69,504 KB
testcase_16 AC 185 ms
70,016 KB
testcase_17 AC 542 ms
76,800 KB
testcase_18 AC 752 ms
76,764 KB
testcase_19 AC 213 ms
71,124 KB
testcase_20 AC 1,363 ms
76,672 KB
testcase_21 AC 1,381 ms
76,604 KB
testcase_22 AC 1,575 ms
76,544 KB
testcase_23 AC 1,367 ms
76,416 KB
testcase_24 AC 1,335 ms
76,596 KB
testcase_25 AC 1,348 ms
76,264 KB
testcase_26 AC 1,417 ms
76,800 KB
testcase_27 AC 34 ms
52,492 KB
testcase_28 AC 1,072 ms
76,612 KB
testcase_29 AC 2,885 ms
76,092 KB
testcase_30 AC 2,916 ms
76,472 KB
testcase_31 AC 36 ms
51,968 KB
testcase_32 AC 35 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
    i += 1
  return cd

def divisor2(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i!=n//i:
        cd.append(n//i)
    i += 1
  return cd

def check(bpc,bmc):
  if (bpc+bmc)%2==1:
    return False
  if bpc-bmc<=0:
    return False
  return True

def solve():
  S = int(input())
  ans = [0]*S
  for s in range(S):
    X, Y = map(int, input().split())
    q = abs(X-Y)
    p = X+Y
    if q==0:
      if p%2==0:
        ans[s] += p//2 - 1
        ans[s] += len(divisor2(p//2))-1
      if p%4==0:
        ans[s] -= 1
      continue
    divs = divisor(q)
    for div in divs:
      div2 = q//div
      if p%(div+2)==0:
        bpc = p//(div+2)
        bmc = div2
        if check(bpc,bmc):
          ans[s] += 1
      if p%(div2+2)==0:
        bpc = p//(div2+2)
        bmc = div
        if check(bpc,bmc):
          ans[s] += 1
  return ans
print(*solve(),sep='\n')
0