結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー StanMarshStanMarsh
提出日時 2023-11-25 15:26:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 7,435 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 81,944 KB
実行使用メモリ 209,568 KB
最終ジャッジ日時 2024-09-26 10:51:53
合計ジャッジ時間 7,495 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 231 ms
141,692 KB
testcase_01 AC 304 ms
184,192 KB
testcase_02 AC 218 ms
132,064 KB
testcase_03 AC 289 ms
177,272 KB
testcase_04 AC 300 ms
183,584 KB
testcase_05 AC 180 ms
106,404 KB
testcase_06 AC 324 ms
187,136 KB
testcase_07 AC 330 ms
199,228 KB
testcase_08 AC 272 ms
165,472 KB
testcase_09 AC 359 ms
209,568 KB
testcase_10 AC 214 ms
127,252 KB
testcase_11 AC 263 ms
156,948 KB
testcase_12 AC 344 ms
200,060 KB
testcase_13 AC 229 ms
136,344 KB
testcase_14 AC 207 ms
121,236 KB
testcase_15 AC 135 ms
90,320 KB
testcase_16 AC 139 ms
90,360 KB
testcase_17 AC 198 ms
114,456 KB
testcase_18 AC 134 ms
90,408 KB
testcase_19 AC 136 ms
90,392 KB
testcase_20 AC 135 ms
90,396 KB
testcase_21 AC 135 ms
90,468 KB
testcase_22 AC 139 ms
90,340 KB
testcase_23 AC 135 ms
90,672 KB
testcase_24 AC 137 ms
90,332 KB
testcase_25 AC 136 ms
90,376 KB
testcase_26 AC 138 ms
90,292 KB
testcase_27 AC 138 ms
90,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import getrandbits, randrange
from string import ascii_lowercase, ascii_uppercase
import sys
from math import ceil, floor, sqrt, pi, factorial, gcd, log, log10, log2, inf, cos, sin
from copy import deepcopy, copy
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import (
    accumulate,
    product,
    combinations,
    combinations_with_replacement,
    permutations,
)
from bisect import bisect, bisect_left, bisect_right
from functools import lru_cache, reduce
from decimal import Decimal, getcontext
from typing import List, Tuple, Optional


inf = float("inf")


def ceil_div(a, b):
    return (a + b - 1) // b


def isqrt(num):
    res = int(sqrt(num))
    while res * res > num:
        res -= 1
    while (res + 1) * (res + 1) <= num:
        res += 1
    return res


def int1(s):
    return int(s) - 1


from types import GeneratorType


def bootstrap(f, stack=[]):
    def wrapped(*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 wrapped


import sys
import os

input = lambda: sys.stdin.readline().rstrip("\r\n")

print = lambda *args, end="\n", sep=" ": sys.stdout.write(
    sep.join(map(str, args)) + end
)


def II():
    return int(input())


def MII(base=0):
    return map(lambda s: int(s) - base, input().split())


def LII(base=0):
    return list(MII(base))


def NA():
    n = II()
    a = LII()
    return n, a


def read_graph(n, m, base=0, directed=False, return_edges=False):

    g = [[] for _ in range(n)]
    edges = []
    for _ in range(m):
        a, b = MII(base)
        if return_edges:
            edges.append((a, b))
        g[a].append(b)
        if not directed:
            g[b].append(a)
    if return_edges:
        return g, edges
    return g


def read_graph_with_weight(n, m, base=0, directed=False, return_edges=False):

    g = [[] for _ in range(n)]
    edges = []
    for _ in range(m):
        a, b, w = MII()
        a, b = a - base, b - base
        if return_edges:
            edges.append((a, b, w))
        g[a].append((b, w))
        if not directed:
            g[b].append((a, w))
    if return_edges:
        return g, edges
    return g


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


tokens = None


def NI():
    global tokens
    if tokens is None:
        tokens = iterate_tokens()
    return int(next(tokens))


def LNI(n):
    return [NI() for _ in range(n)]


def yes(res):
    print("Yes" if res else "No")


def YES(res):
    print("YES" if res else "NO")


def pairwise(a):
    n = len(a)
    for i in range(n - 1):
        yield a[i], a[i + 1]


def factorial(n):
    return reduce(lambda x, y: x * y, range(1, n + 1))


def cmin(dp, i, x):
    if x < dp[i]:
        dp[i] = x


def cmax(dp, i, x):
    if x > dp[i]:
        dp[i] = x


def alp_a_to_i(s):
    return ord(s) - ord("a")


def alp_A_to_i(s):
    return ord(s) - ord("A")


def alp_i_to_a(i):
    return chr(ord("a") + i)


def alp_i_to_A(i):
    return chr(ord("A") + i)


d4 = [(1, 0), (0, 1), (-1, 0), (0, -1)]
d8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]


def ranges(n, m):
    return ((i, j) for i in range(n) for j in range(m))


def valid(i, j, n, m):
    return 0 <= i < n and 0 <= j < m


def ninj(i, j, n, m):
    return [(i + di, j + dj) for di, dj in d4 if valid(i + di, j + dj, n, m)]


def gen(x, *args):
    if len(args) == 1:
        return [x] * args[0]
    if len(args) == 2:
        return [[x] * args[1] for _ in [0] * args[0]]
    if len(args) == 3:
        return [[[x] * args[2] for _ in [0] * args[1]] for _ in [0] * args[0]]
    if len(args) == 4:
        return [
            [[[x] * args[3] for _ in [0] * args[2]] for _ in [0] * args[1]]
            for _ in [0] * args[0]
        ]


list2d = lambda a, b, v: [[v] * b for _ in range(a)]
list3d = lambda a, b, c, v: [[[v] * c for _ in range(b)] for _ in range(a)]


class Debug:
    def __init__(self, debug=False):
        self.debug = debug
        cur_path = os.path.dirname(os.path.abspath(__file__))
        self.local = os.path.exists(cur_path + "/.cph")

    def get_ic(self):
        if self.debug and self.local:
            from icecream import ic

            return ic
        else:
            return lambda *args, **kwargs: ...


class PrimeTable:
    def __init__(self, n: int) -> None:
        self.n = n
        self.primes = []
        self.isprime = [True] * (n + 1)
        self.isprime[0] = self.isprime[1] = False
        self.max_div = list(range(n + 1))
        self.max_div[1] = 1

        self.phi = list(range(n + 1))

        for i in range(2, n + 1):
            if self.max_div[i] == i:
                self.primes.append(i)
                for j in range(i, n + 1, i):
                    if j != i:
                        self.isprime[j] = False
                    self.max_div[j] = i
                    self.phi[j] = self.phi[j] // i * (i - 1)
        self.pres = [0]
        for v in self.isprime:
            if v:
                self.pres.append(self.pres[-1] + 1)
            else:
                self.pres.append(self.pres[-1])

    def count_primes(self, l, r):

        return self.pres[r + 1] - self.pres[l]

    def is_prime(self, x: int):
        if x < 2:
            return False
        if x <= self.n:
            return self.max_div[x] == x
        for p in self.primes:
            if p * p > x:
                break
            if x % p == 0:
                return False
        return True

    def prime_factorization(self, x: int):
        if x > self.n:
            for p in self.primes:
                if p * p > x:
                    break
                if x <= self.n:
                    break
                if x % p == 0:
                    cnt = 0
                    while x % p == 0:
                        cnt += 1
                        x //= p
                    yield p, cnt
        while 1 < x and x <= self.n:
            p, cnt = self.max_div[x], 0
            while x % p == 0:
                cnt += 1
                x //= p
            yield p, cnt
        if x >= self.n and x > 1:
            yield x, 1

    def get_factors(self, x: int):
        factors = [1]
        for p, b in self.prime_factorization(x):
            n = len(factors)
            for j in range(1, b + 1):
                for d in factors[:n]:
                    factors.append(d * (p**j))
        return factors


class PrefixSum:
    def __init__(self, a):
        self.n = len(a)
        self.sum = [0] * (self.n + 1)
        self.sum[1] = a[0]
        for i in range(2, self.n + 1):
            self.sum[i] = self.sum[i - 1] + a[i - 1]

    def get_sum(self, l, r):

        return self.sum[r + 1] - self.sum[l]

    def __repr__(self):
        return str(self.sum)


ic = Debug(1).get_ic()
n = II()

pt = PrimeTable(n + 1)
t = [max(0, i - 1) for i in pt.phi]
pre = PrefixSum(t)


res = 0
for i in range(2, n):
    m = n // i
    res += pre.get_sum(0, m)

print(res)
0