結果

問題 No.1746 Sqrt Integer Segments
ユーザー mkawa2
提出日時 2021-11-18 03:17:56
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,023 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 1,705,216 KB
最終ジャッジ日時 2024-12-24 15:16:01
合計ジャッジ時間 49,899 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 2
other AC * 12 TLE * 9 MLE * 7
権限があれば一括ダウンロードができます

ソースコード

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

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)
ptoi = {p: i for i, p in enumerate(sv.plist)}
ss = []
ans = 0
for a in aa:
    pe = sv.pfct(a)
    cur = 0
    for p, e in pe:
        if e & 1:
            i = ptoi[p]
            cur |= 1 << i
    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