LoginSignup
0
0

More than 3 years have passed since last update.

はじめに

A~Dの四完でした。

A問題

問題

考えたこと
やるだけ

a, b = map(int,input().split())
print(a*b)

B問題

問題

考えたこと
0が入ってると積は0なのでsortで小さい順に並べてやる。

n = int(input())
a = list(map(int,input().split()))

a.sort()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        quit()

print(ans)

C問題

問題

考えたこと
はい。こいつのせいでパフォが落ちました。くそ。
精度が不安だったのでdecimal使いました。「decimalの切り捨てはquantize使おうな! 約束だぞ!!!!」

from decimal import *
a, b = input().split()

a = Decimal(a)
b = Decimal(b)
ans = a * b
ans = ans.quantize(Decimal(0),rounding=ROUND_FLOOR)
print(ans)

D問題

問題

考えたこと
とりあえず$N$を素因数分解します。
サンプルケース1の場合を考えます。
24を素因数分解すると$2^3*3^1$となります。このとき行える操作の最大数は$2^1,2^2,3^1$です。$2^3$はNの約数ではないので、できません。$3^2$も同様です。
このことから、$N$の素因数の指数部分を超えないように足していけばいいことが分かります。(例:24だと、2の数は3個なので1+2まで、3の数は1個なので1)。あとは、それぞれの素因数ごとに何回使えるかを計算するだけ。

n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if n == 1:
    print(0)
    quit()
f = factorization(n)
ans = 0
c = len(f)
for i in range(c):
    s = 0
    g = f[i][1]
    if g == 2:
        ans += 1
    else:
        for j in range(g):
            s += j + 1
            f[i][1] -= j+1
            if s > g:
                break
            ans += 1
print(ans)

まとめ

最近のCに嫌われているtax_free。こういう精度問題が出たときに、脳死で提出しまくる癖を直したい。
ではまた、おやすみなさい。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0