結果
| 問題 | 
                            No.1514 Squared Matching
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yassu0320
                         | 
                    
| 提出日時 | 2022-06-05 02:45:45 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,071 bytes | 
| コンパイル時間 | 162 ms | 
| コンパイル使用メモリ | 82,144 KB | 
| 実行使用メモリ | 721,696 KB | 
| 最終ジャッジ日時 | 2024-09-21 03:56:36 | 
| 合計ジャッジ時間 | 5,801 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 1 MLE * 1 -- * 24 | 
ソースコード
#!/usr/bin/env pypy3
from pprint import pprint
from string import ascii_lowercase as letter
from sys import setrecursionlimit, stdin
from typing import Dict, Iterable, Set
INF: int = (1 << 62) - 1
MOD1000000007 = 10**9 + 7
MOD998244353 = 998244353
readline = stdin.readline
input = lambda: stdin.readline().rstrip('\r\n')
def inputs(type_=int):
    ins = input().split()
    if isinstance(type_, Iterable):
        return [t(x) for t, x in zip(type_, ins)]
    else:
        return list(map(type_, ins))
def input_(type_=int):
    a, = inputs(type_)
    return a
def input1() -> int:
    return int(readline())
inputi = input1
def input2():
    a = readline().split()
    assert len(a) == 2
    a[0] = int(a[0])
    a[1] = int(a[1])
    return a
def input3():
    a = readline().split()
    assert len(a) == 3
    a[0] = int(a[0])
    a[1] = int(a[1])
    a[2] = int(a[2])
    return a
def input4():
    a = readline().split()
    assert len(a) == 4
    a[0] = int(a[0])
    a[1] = int(a[1])
    a[2] = int(a[2])
    a[3] = int(a[3])
    return a
yn = ['no', 'yes']
Yn = ['No', 'Yes']
YN = ['NO', 'YES']
# start coding
def isqrt(n):
    """
    nの平方根をニュートン法で求める.
    計算量: O(log(n))以下 (O(loglog(n))?)
    Ref: http://www.ritsumei.ac.jp/se/~osaka/rejime/suuti/suuti2001.pdf
    """
    x, y = n, (n + 1) // 2
    while y < x:
        x, y = y, (y + n // y) // 2
    return x
def factor(n: int) -> Dict[int, int]:
    if n < 2:
        return dict()
    res = dict()
    for i in range(2, isqrt(n) + 1):
        if n % i == 0:
            res[i] = 0
            while n % i == 0:
                res[i] += 1
                n //= i
    if n != 1:
        res[n] = 1
    return res
class Osak:
    def __init__(self, max_n: int) -> None:
        self.max_n = max_n
        self._create_table()
    def _create_table(self):
        """
        (max_n + 1)個の要素を持つリストaであってa[k]がkの最小の素因数であるようなリストをself.tableに設定する.
        計算量: O(max_n * loglog(max_n))
        """
        a = [None] * (self.max_n + 1)
        for k in range(2, self.max_n + 1):
            if a[k] is not None:
                continue
            for p in range(k, self.max_n + 1, k):
                if a[p] is None:
                    a[p] = k
        self.table = a
    def is_prime(self, n: int) -> bool:
        return n >= 2 and self.table[n] == n
    def factor(self, n: int) -> dict:
        assert 0 <= n < len(self.table)
        if n <= 1:
            return {}
        d = {}
        while n != 1:
            k = self.table[n]
            d[k] = 0
            while n % k == 0:
                d[k] += 1
                n //= k
        return d
    def __str__(self) -> str:
        return f'{self.__class__.__name__} <max_n: {self.max_n}>'
n = inputi()
osak = Osak(n)
res = 0
for i in range(1, n + 1):
    d = factor(i)
    t = 1
    for p, c in d.items():
        if c % 2 == 1:
            t *= p
    res += isqrt(n // t)
print(res)
            
            
            
        
            
yassu0320