結果

問題 No.1746 Sqrt Integer Segments
ユーザー mkawa2mkawa2
提出日時 2021-11-18 09:05:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 593 ms / 2,000 ms
コード長 2,015 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 178,708 KB
最終ジャッジ日時 2023-10-11 10:40:16
合計ジャッジ時間 14,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
101,832 KB
testcase_01 AC 176 ms
101,852 KB
testcase_02 AC 469 ms
150,280 KB
testcase_03 AC 344 ms
122,808 KB
testcase_04 AC 404 ms
132,568 KB
testcase_05 AC 581 ms
172,972 KB
testcase_06 AC 326 ms
117,612 KB
testcase_07 AC 258 ms
106,092 KB
testcase_08 AC 455 ms
146,640 KB
testcase_09 AC 568 ms
178,708 KB
testcase_10 AC 310 ms
116,520 KB
testcase_11 AC 541 ms
162,948 KB
testcase_12 AC 580 ms
173,576 KB
testcase_13 AC 593 ms
173,400 KB
testcase_14 AC 582 ms
173,872 KB
testcase_15 AC 582 ms
173,752 KB
testcase_16 AC 586 ms
172,876 KB
testcase_17 AC 423 ms
141,332 KB
testcase_18 AC 221 ms
115,824 KB
testcase_19 AC 224 ms
115,816 KB
testcase_20 AC 219 ms
115,520 KB
testcase_21 AC 263 ms
108,512 KB
testcase_22 AC 261 ms
109,116 KB
testcase_23 AC 230 ms
106,344 KB
testcase_24 AC 339 ms
126,756 KB
testcase_25 AC 346 ms
126,624 KB
testcase_26 AC 342 ms
126,796 KB
testcase_27 AC 466 ms
133,296 KB
testcase_28 AC 465 ms
136,424 KB
testcase_29 AC 440 ms
126,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
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 = 18446744073709551615
# inf = 4294967295
md = 10**9+7
# md = 998244353

from random import randrange

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        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

    # これが素因数分解(prime factorization)
    def pfct(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 [(p, e) for p, e in zip(pp, ee)]

from collections import Counter

n = II()
aa = LI()

sv = Sieve(1000005)
enc = {p: randrange(inf) for p in sv.plist}
ss = []
ans = 0
for a in aa:
    pe = sv.pfct(a)
    cur = 0
    for p, e in pe:
        if e & 1: cur ^= enc[p]
    ss.append(cur)

cnt = Counter()
cnt[0] = 1
ans = 0
x = 0
for s in ss:
    x ^= s
    ans += cnt[x]
    cnt[x] += 1

print(ans)
0