結果

問題 No.982 Add
ユーザー tobusakanatobusakana
提出日時 2020-08-30 10:01:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 10,776 KB
実行使用メモリ 8,432 KB
最終ジャッジ日時 2023-08-09 10:48:31
合計ジャッジ時間 3,459 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,224 KB
testcase_01 AC 46 ms
8,400 KB
testcase_02 AC 17 ms
8,176 KB
testcase_03 AC 16 ms
8,256 KB
testcase_04 AC 15 ms
8,224 KB
testcase_05 AC 35 ms
8,280 KB
testcase_06 AC 18 ms
8,284 KB
testcase_07 AC 23 ms
8,220 KB
testcase_08 AC 17 ms
8,128 KB
testcase_09 AC 123 ms
8,128 KB
testcase_10 AC 92 ms
8,084 KB
testcase_11 AC 19 ms
8,100 KB
testcase_12 AC 16 ms
8,280 KB
testcase_13 AC 16 ms
8,104 KB
testcase_14 AC 15 ms
8,112 KB
testcase_15 AC 19 ms
8,268 KB
testcase_16 AC 35 ms
8,116 KB
testcase_17 AC 18 ms
8,232 KB
testcase_18 AC 15 ms
8,284 KB
testcase_19 AC 16 ms
8,204 KB
testcase_20 AC 15 ms
8,432 KB
testcase_21 AC 15 ms
8,228 KB
testcase_22 AC 16 ms
8,424 KB
testcase_23 AC 15 ms
8,224 KB
testcase_24 AC 184 ms
8,212 KB
testcase_25 AC 172 ms
8,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

# どちらかが1であれば0
# 互いに素でなければ-1
# 互いに素なら、公倍数までの作れない数を数える

A,B = map(int,readline().split())
if A == 1 or B == 1:
  print(0)
  exit(0)
  
import math
g = math.gcd(A,B)
if g != 1:
  print(-1)
  exit(0)
  
L = A // g * B

ans = 0
for i in range(1, L + 1):
  for a in range(L // A + 1):
    candi = i - a * A
    if (candi == 0) or (candi > 0 and candi % B == 0):
      break
  else:
    ans += 1

print(ans)
0