結果

問題 No.1746 Sqrt Integer Segments
ユーザー mkawa2mkawa2
提出日時 2021-11-18 09:04:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,015 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 149,464 KB
最終ジャッジ日時 2023-08-26 16:22:16
合計ジャッジ時間 12,996 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
100,128 KB
testcase_01 AC 151 ms
100,092 KB
testcase_02 WA -
testcase_03 AC 250 ms
110,088 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 239 ms
105,972 KB
testcase_07 AC 198 ms
103,400 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 191 ms
115,608 KB
testcase_19 AC 187 ms
115,508 KB
testcase_20 AC 191 ms
115,752 KB
testcase_21 AC 229 ms
107,744 KB
testcase_22 AC 227 ms
107,616 KB
testcase_23 AC 205 ms
104,128 KB
testcase_24 AC 303 ms
127,880 KB
testcase_25 AC 295 ms
127,956 KB
testcase_26 AC 300 ms
127,756 KB
testcase_27 AC 328 ms
127,876 KB
testcase_28 AC 324 ms
127,884 KB
testcase_29 AC 331 ms
127,844 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