結果

問題 No.1746 Sqrt Integer Segments
ユーザー ygd.ygd.
提出日時 2021-11-19 23:55:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,026 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 107,712 KB
最終ジャッジ日時 2023-08-30 11:35:43
合計ジャッジ時間 11,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
73,232 KB
testcase_01 AC 114 ms
73,284 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 154 ms
106,820 KB
testcase_19 AC 156 ms
107,128 KB
testcase_20 AC 158 ms
107,012 KB
testcase_21 AC 389 ms
92,756 KB
testcase_22 AC 383 ms
92,448 KB
testcase_23 AC 258 ms
84,956 KB
testcase_24 AC 650 ms
107,540 KB
testcase_25 AC 654 ms
107,468 KB
testcase_26 AC 648 ms
107,156 KB
testcase_27 AC 271 ms
107,096 KB
testcase_28 AC 270 ms
107,024 KB
testcase_29 AC 260 ms
107,096 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 20 #pow(10,6)
    PL,dummy = prime_list(MAX)
    #素数 -> index
    prime_idx = {}
    for i,p in enumerate(PL):
        prime_idx[p] = i

    Z = []
    zobrist_hash = 0
    for _ in range(len(PL)):
        #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 a in A:
        P = prime_factorize(a)
        for soin,jo in P:
            if jo%2 == 0: continue #偶数なので不変
            #print(key,val)
            idx = prime_idx[soin]
            zobrist_hash ^= Z[idx]
        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)
                

def prime_factorize(n):
    ret = []
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    if cnt > 0:
        ret.append((2,cnt))
    i = 3
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            cnt += 1
            n //= i
        else:
            ret.append((i,cnt))
            i += 2
    if n != 1:
        ret.append((n,1)) 
    return ret #(素因数、何乗)

if __name__ == '__main__':
    main()
0