- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 70 lines of Python from the credited upstream file abc215_d.py.
- The implementation visibly relies on sequence storage, hash lookup, ordered lookup.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def run_prime_factorization(max_number: int) -> dict:5 '''Run prime factorization.6 Args:7 max_number: Int of number (greater than 1).8 Returns:9 A dictionary's items ((base, exponent) pairs).10 Landau notation: O(log n)11 '''12 13 from math import sqrt14 15 ans = dict()16 remain = max_number17 18 for base in range(2, int(sqrt(max_number)) + 1):19 if remain % base == 0:20 exponent_count = 021 22 while remain % base == 0:23 exponent_count += 124 remain = base25 26 ans[base] = exponent_count27 28 if remain != 1:29 ans[remain] = 130 31 return ans32 33 34def main():35 import sys36 37 input = sys.stdin.readline38 39 n, m = map(int, input().split())40 a = list(map(int, input().split()))41 p = set()42 43 for ai in a:44 results = run_prime_factorization(ai)45 46 for r in results.keys():47 p.add(r)48 49 ans = [True] * (m + 1)50 ans[0] = False51 52 for pi in p:53 tmp = pi54 55 while tmp <= m:56 ans[tmp] = False57 tmp += pi58 59 count = sum(ans)60 61 print(count)62 63 for index, _a in enumerate(ans):64 if _a:65 print(index)66 67 68if __name__ == "__main__":69 main()70