From 33ea17f644675411389e7cf0e33c361b663965bd Mon Sep 17 00:00:00 2001 From: Yawn-Sean <1900015431@pku.edu.cn> Date: Thu, 7 Mar 2024 09:24:08 +0800 Subject: [PATCH] 20240307 Yawn Sean's submission for CF453 --- .../personal_submission/cf453a_yawn_sean.py | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 daily_problems/2024/03/0307/personal_submission/cf453a_yawn_sean.py diff --git a/daily_problems/2024/03/0307/personal_submission/cf453a_yawn_sean.py b/daily_problems/2024/03/0307/personal_submission/cf453a_yawn_sean.py new file mode 100644 index 0000000000..3ee24af44d --- /dev/null +++ b/daily_problems/2024/03/0307/personal_submission/cf453a_yawn_sean.py @@ -0,0 +1,188 @@ +standard_input, packages, output_together = 1, 1, 1 +dfs, hashing, read_from_file = 0, 0, 0 +de = 1 + +if 1: + + if standard_input: + import io, os, sys + input = lambda: sys.stdin.readline().strip() + + import math + inf = math.inf + + def I(): + return input() + + def II(): + return int(input()) + + def MII(): + return map(int, input().split()) + + def LI(): + return list(input().split()) + + def LII(): + return list(map(int, input().split())) + + def LFI(): + return list(map(float, input().split())) + + def GMI(): + return map(lambda x: int(x) - 1, input().split()) + + def LGMI(): + return list(map(lambda x: int(x) - 1, input().split())) + + if packages: + from io import BytesIO, IOBase + + import random + import os + + import bisect + import typing + from collections import Counter, defaultdict, deque + from copy import deepcopy + from functools import cmp_to_key, lru_cache, reduce + from heapq import merge, heapify, heappop, heappush, heappushpop, nlargest, nsmallest + from itertools import accumulate, combinations, permutations, count, product + from operator import add, iand, ior, itemgetter, mul, xor + from string import ascii_lowercase, ascii_uppercase, ascii_letters + from typing import * + BUFSIZE = 4096 + + if output_together: + class FastIO(IOBase): + newlines = 0 + + def __init__(self, file): + self._fd = file.fileno() + self.buffer = BytesIO() + self.writable = "x" in file.mode or "r" not in file.mode + self.write = self.buffer.write if self.writable else None + + def read(self): + while True: + b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) + if not b: + break + ptr = self.buffer.tell() + self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) + self.newlines = 0 + return self.buffer.read() + + def readline(self): + while self.newlines == 0: + b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) + self.newlines = b.count(b"\n") + (not b) + ptr = self.buffer.tell() + self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) + self.newlines -= 1 + return self.buffer.readline() + + def flush(self): + if self.writable: + os.write(self._fd, self.buffer.getvalue()) + self.buffer.truncate(0), self.buffer.seek(0) + + class IOWrapper(IOBase): + def __init__(self, file): + self.buffer = FastIO(file) + self.flush = self.buffer.flush + self.writable = self.buffer.writable + self.write = lambda s: self.buffer.write(s.encode("ascii")) + self.read = lambda: self.buffer.read().decode("ascii") + self.readline = lambda: self.buffer.readline().decode("ascii") + + sys.stdout = IOWrapper(sys.stdout) + + if dfs: + from types import GeneratorType + + def bootstrap(f, stack=[]): + def wrappedfunc(*args, **kwargs): + if stack: + return f(*args, **kwargs) + else: + to = f(*args, **kwargs) + while True: + if type(to) is GeneratorType: + stack.append(to) + to = next(to) + else: + stack.pop() + if not stack: + break + to = stack[-1].send(to) + return to + return wrappedfunc + + if hashing: + RANDOM = random.getrandbits(20) + class Wrapper(int): + def __init__(self, x): + int.__init__(x) + + def __hash__(self): + return super(Wrapper, self).__hash__() ^ RANDOM + + if read_from_file: + file = open("input.txt", "r").readline().strip()[1:-1] + fin = open(file, 'r') + input = lambda: fin.readline().strip() + output_file = open("output.txt", "w") + def fprint(*args, **kwargs): + print(*args, **kwargs, file=output_file) + + if de: + def debug(*args, **kwargs): + print('\033[92m', end='') + print(*args, **kwargs) + print('\033[0m', end='') + +pre_process = [None] * 11 +for b in range(2, 11): + length = 1 + cur = 1 + while cur <= 10 ** 18: + length += 1 + cur *= b + + length -= 1 + pre_process[b] = [[0] * (1 << b) for _ in range(length)] + for i in range(b): + pre_process[b][0][1 << i] = 1 + + for i in range(length - 1): + for msk in range(1 << b): + for new_bit in range(b): + pre_process[b][i + 1][msk ^ (1 << new_bit)] += pre_process[b][i][msk] + + for i in range(1, length): + for msk in range(1 << b): + pre_process[b][i][msk] -= pre_process[b][i - 1][msk ^ 1] + +def main(): + b, l, r = MII() + + def f(x): + vals = [] + while x: + vals.append(x % b) + x //= b + vals.reverse() + k = len(vals) + + ans = 0 + for i in range(k - 1): + ans += pre_process[b][i][0] + return 0 + + print(f(r + 1) - f(l)) + return + +t = II() +for _ in range(t): + main() \ No newline at end of file