結果

問題 No.1746 Sqrt Integer Segments
ユーザー ygd.ygd.
提出日時 2021-11-19 21:36:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,901 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 459,692 KB
最終ジャッジ日時 2023-08-30 07:39:27
合計ジャッジ時間 7,931 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline
from collections import defaultdict
import random

def prime_list(n):
    is_prime = [0] * (n + 1) #素数かどうか。1なら素数。
    is_prime[2] = 1
    for i in range(3, n + 1, 2):
        is_prime[i] = 1
    for i in range(2, int(n ** 0.5) + 1):
        if is_prime[i]:
            for j in range(i * i, n + 1, 2 * i):
                is_prime[j] = 0
    #最後に全部並べる。
    d = []
    for j in range(n + 1):
        if is_prime[j] == 1:
            d.append(j)
    return d, is_prime

def main():
    n = int(input())
    A = list(map(int,input().split()))
    MAX = pow(10,6)
    P,dummy = prime_list(MAX)
    soinsu = [defaultdict(int) for _ in range(MAX+1)]
    prime_idx = {}
    for i,p in enumerate(P):
        v = p
        prime_idx[p] = i
        while v <= MAX:
            cnt = 0
            nv = v
            while nv%p == 0:
                nv //= p
                cnt += 1
            soinsu[v][i] = cnt #i番目の素数の因数をいくつ持つか
            v += p
    #print(soinsu)
    Z = []
    zobrist_hash = 0
    for _ in range(len(P)):
        #long longの範囲でランダムにハッシュを取る
        temp = random.randrange((1<<62) + 1,1<<63)
        Z.append(temp)
        zobrist_hash ^= temp

    dic = defaultdict(int)
    #ret = []
    #ret.append(zobrist_hash)
    dic[zobrist_hash] += 1
    for i,a in enumerate(A):
        #print("A",a)
        for key,val in soinsu[a].items():
            if val%2 == 0: continue #偶数なので不変
            #print(key,val)
            zobrist_hash ^= Z[key]
        dic[zobrist_hash] += 1
        #ret.append(zobrist_hash)
    #print(ret)
            
    ans = 0
    #print(dic)
    for key,val in dic.items():
        ans += val*(val-1)//2
    print(ans)
               
if __name__ == '__main__':
    main()
0