import collections import decimal import math import sys import time #mod = 1_000_000_007 def resolve(): inp = int2d() n,m = inp[0] graph = [[0]*n for _ in range(n)] for item1,item2,score in inp[1:]: graph[item1][item2] = score #bit, last vertex dp = [[0]*n for _ in range(1< [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] if n <= 1: return [] if n == 2: return [2] deq = collections.deque([2]) sqrt_i = int(decimal.Decimal(n).sqrt())//2 isprime = [True] * math.ceil(n/2)#i => 2i+1 len_is_prime = len(isprime) for i in range(1, len_is_prime): if not isprime[i]: continue deq.append(2*i+1) if i>sqrt_i: continue for j in range(2*i*(i+1), len_is_prime, 2*i+1): isprime[j] = False return list(deq) def alldevisor(n): # 30 => [1, 2, 3, 5, 6, 10, 15, 30] if n == 1:return[1] l, r = collections.deque([1]), collections.deque([n]) tmp = 2 while(tmp**2 <= n): if n%tmp == 0: l.append(tmp) if n != tmp**2: r.appendleft(n//tmp) tmp += 1 return list(l+r) def factorization(n, prime_iterable = None): # 48 => [(2,4), (3,1)] seq = prime_iterable if prime_iterable != None else range(2,n) l = [] for prime in seq: if prime * prime > n: break cnt = 0 while n % prime ==0: n //= prime cnt += 1 if cnt > 0: l.append((prime, cnt)) if n > 1: l.append((n, 1)) return l #endregion class SegTree: """ reffered to 'maspy', noncommutative operation is available X_f = min, X_unit = INF X_f = max, X_unit = -INF X_f = sum, X_unit = 0 X_f = lambda _,a,b: a+b, X_unit = '' """ X_unit = '' X_f = lambda _,a,b:a+b def __init__(self, seq): l = list(seq) self.N = len(l) self.X = [self.X_unit] * self.N + l for i in range(self.N - 1, 0, -1): self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def set_val(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def fold(self, L, R):#[L,R) L += self.N R += self.N vL = self.X_unit vR = self.X_unit while L < R: if L & 1: vL = self.X_f(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.X_f(self.X[R], vR) L >>= 1 R >>= 1 return self.X_f(vL, vR) #endregion resolve()