ABC169に参加した。
ERROR: The request could not be satisfied
A – Multiplication 1
やるだけ。
a, b = map(int, input().split())
print(a * b)
B – Multiplication 2
10^18を超えたら-1を出力してループを終えるようにするが、0になるコーナーケースに注意する。
10^18を超えた後に0が出てくるかもしれないので、0があったら答えは0になる。
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
print(0)
else:
ans = 1
for i in a:
ans *= i
if ans > 10 ** 18:
print(-1)
exit()
print(ans)
C – Multiplication 3
言語仕様の問題?
floatでは精度が足りないので、Decimalを使う。
from decimal import Decimal
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
ans = (a * b) // 1
print(ans)
D – Div Game
Nを素因数分解し、各約数の指数を1,2,3,…と減らしていくことが出来る回数。
from collections import Counter
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
n = int(input())
p = prime_factorize(n)
c = Counter(p)
ans = 0
for key, value in c.most_common():
x = 1
while x <= c[key]:
ans += 1
c[key] -= x
x += 1
print(ans)
久々に緑パフォーマンスを出すことが出来てちょっと嬉しい。

コメント