結果
問題 | No.1514 Squared Matching |
ユーザー | mkawa2 |
提出日時 | 2022-12-09 13:14:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,781 ms / 4,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 454,756 KB |
最終ジャッジ日時 | 2024-10-14 18:38:38 |
合計ジャッジ時間 | 53,002 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,480 KB |
testcase_01 | AC | 2,864 ms
454,528 KB |
testcase_02 | AC | 39 ms
52,096 KB |
testcase_03 | AC | 38 ms
52,864 KB |
testcase_04 | AC | 38 ms
52,480 KB |
testcase_05 | AC | 47 ms
60,800 KB |
testcase_06 | AC | 92 ms
69,888 KB |
testcase_07 | AC | 554 ms
141,312 KB |
testcase_08 | AC | 2,748 ms
440,192 KB |
testcase_09 | AC | 2,498 ms
393,088 KB |
testcase_10 | AC | 2,962 ms
420,352 KB |
testcase_11 | AC | 3,019 ms
435,328 KB |
testcase_12 | AC | 3,781 ms
445,696 KB |
testcase_13 | AC | 3,289 ms
450,688 KB |
testcase_14 | AC | 2,840 ms
452,736 KB |
testcase_15 | AC | 3,440 ms
453,888 KB |
testcase_16 | AC | 3,377 ms
454,436 KB |
testcase_17 | AC | 2,865 ms
454,272 KB |
testcase_18 | AC | 2,937 ms
454,676 KB |
testcase_19 | AC | 2,837 ms
454,400 KB |
testcase_20 | AC | 2,836 ms
454,656 KB |
testcase_21 | AC | 2,887 ms
454,756 KB |
testcase_22 | AC | 585 ms
145,024 KB |
testcase_23 | AC | 1,142 ms
223,744 KB |
testcase_24 | AC | 1,764 ms
297,956 KB |
testcase_25 | AC | 2,287 ms
376,064 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class Sieve: def __init__(self, n): self.plist = [2] min_prime_factor = [2, 0]*(n//2+1) for x in range(3, n+1, 2): if min_prime_factor[x] == 0: min_prime_factor[x] = x self.plist.append(x) if x**2 > n: continue for y in range(x**2, n+1, 2*x): if min_prime_factor[y] == 0: min_prime_factor[y] = x self.min_prime_factor = min_prime_factor def isprime(self, x): return self.min_prime_factor[x] == x def pf(self, x): pp, ee = [], [] while x > 1: mpf = self.min_prime_factor[x] if pp and mpf == pp[-1]: ee[-1] += 1 else: pp.append(mpf) ee.append(1) x //= mpf return pp, ee # unsorted def factor(self, a): ff = [1] pp, ee = self.pf(a) for p, e in zip(pp, ee): ff, gg = [], ff w = p for _ in range(e): for f in gg: ff.append(f*w) w *= p ff += gg return ff memo = {} def floor_sqrt(x): if x in memo: return memo[x] a = round(x**0.5-0.49) while a**2 > x: a -= 1 memo[x] = a return a n = II() aa = list(range(n+1)) sq = floor_sqrt(n) sv = Sieve(sq) pp = sv.plist for p in pp: d = p2 = p*p while d <= n: for i in range(d, n+1, d): aa[i] //= p2 d *= p2 # pDB(aa) ans = 0 for i in range(1, n+1): ans += floor_sqrt(n//aa[i]) print(ans)