Solve ABC169 in Python

Introduction

It was four completes from A to D.

A problem

Problem

** Thoughts ** Just do

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

B problem

Problem

** Thoughts ** If 0 is included, the product is 0, so sort them in ascending order.

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 problem

Problem

** Thoughts ** Yes. Because of this guy, the performance has fallen. Fuck. I was worried about the accuracy, so I used decimal. "Let's use quantize to truncate decimal! It's a promise !!!!"

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 problem

Problem

** Thoughts ** For the time being, factor $ N $ into prime factors. Consider the case of sample case 1. Factoring 24 into $ 2 ^ 3 * 3 ^ 1 $. The maximum number of operations that can be performed at this time is $ 2 ^ 1,2 ^ 2,3 ^ 1 $. $ 2 ^ 3 $ is not a divisor of N, so you can't. The same is true for $ 3 ^ 2 $. From this, we can see that we should add them so that they do not exceed the exponential part of the prime factor of $ N $. (Example: In the case of 24, the number of 2 is 3 so it is up to 1 + 2, and the number of 3 is 1 so 1). All you have to do now is calculate how many times you can use each prime factor.

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)

Summary

Tax_free hated by C these days. I want to correct the habit of submitting due to brain death when such accuracy problems occur. See you again, good night.

Recommended Posts

Solve ABC169 in Python
Solve ABC175 D in Python
Solve Atcoder ABC169 A-D in Python
Solve ABC036 A ~ C in Python
Solve ABC037 A ~ C in Python
Solve ABC146-C in Python
Solve ABC098-C in Python
Solve ABC159-D in Python
Solve ABC160-E in Python
ABC 157 D --Solve Friend Suggestions in Python!
I wanted to solve ABC159 in Python
Solve ABC165 A, B, D in Python
Solve AtCoder ABC166 with python
Atcoder ABC164 A-C in Python
Atcoder ABC167 A-D in Python
Solve Wooldridge exercises in Python
Atcoder ABC166 A-E in Python
Solve optimization problems in Python
Solve AtCoder ABC 186 with Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC176 (A, B, C, E) in Python
Solve ABC163 A ~ C with Python
Solve ABC166 A ~ D with Python
Solve ABC168 A ~ C with Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve ordinary differential equations in Python
Beginner ABC154 (Python)
Quadtree in Python --2
Python in optimization
Beginner ABC156 (Python)
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
AtCoder ABC 174 Python
AtCoder ABC187 Python
Epoch in Python
Discord in Python
Sudoku in Python
nCr in python
N-Gram in Python
AtCoder ABC188 Python
Programming in python
Beginner ABC155 (Python)
Plink in Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
Beginner ABC157 (Python)
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.