結果

問題 No.434 占い
ユーザー titiatitia
提出日時 2023-04-25 06:36:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,038 ms / 2,000 ms
コード長 1,239 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-04-26 14:43:55
合計ジャッジ時間 16,820 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
18,560 KB
testcase_01 AC 152 ms
18,688 KB
testcase_02 AC 153 ms
18,560 KB
testcase_03 AC 157 ms
18,688 KB
testcase_04 AC 162 ms
18,432 KB
testcase_05 AC 167 ms
18,432 KB
testcase_06 AC 177 ms
18,432 KB
testcase_07 AC 173 ms
18,432 KB
testcase_08 AC 239 ms
18,432 KB
testcase_09 AC 234 ms
18,560 KB
testcase_10 AC 221 ms
18,688 KB
testcase_11 AC 213 ms
18,560 KB
testcase_12 AC 250 ms
18,560 KB
testcase_13 AC 252 ms
18,560 KB
testcase_14 AC 232 ms
18,688 KB
testcase_15 AC 1,038 ms
18,432 KB
testcase_16 AC 915 ms
18,688 KB
testcase_17 AC 818 ms
18,688 KB
testcase_18 AC 724 ms
18,432 KB
testcase_19 AC 624 ms
18,560 KB
testcase_20 AC 887 ms
18,432 KB
testcase_21 AC 1,009 ms
18,688 KB
testcase_22 AC 882 ms
18,432 KB
testcase_23 AC 164 ms
18,432 KB
testcase_24 AC 835 ms
18,560 KB
testcase_25 AC 177 ms
18,560 KB
testcase_26 AC 531 ms
18,560 KB
testcase_27 AC 722 ms
18,560 KB
testcase_28 AC 745 ms
18,560 KB
testcase_29 AC 647 ms
18,688 KB
testcase_30 AC 822 ms
18,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# エラトステネスの篩を用いた素因数分解・約数列挙
MAX=2*10**5+10 # 使いたい最大値を指定

# Sieve[i]で、iの最も小さい約数を返す。
Sieve=[i for i in range(MAX)]

for i in range(2,MAX):
    if Sieve[i]!=i:
        continue
    
    for j in range(i,MAX,i):
        if Sieve[j]==j:
            Sieve[j]=i

# 素因数分解
def fact(x):
    D=dict()
    while x!=1:
        k=Sieve[x]
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        x//=k
    return D

T=int(input())
for tests in range(T):
    S=list(map(int,list(input())))

    if S==[0]*len(S):
        print(0)
        continue

    LIST=[0]*9

    ANS=0

    for i in range(len(S)):
        if i==0 or i==len(S)-1:
            ANS=(ANS+S[i])%9
            continue

        D=fact(i)
        #print(D)

        for x in D:
            LIST[x%9]-=D[x]

        D=fact(len(S)-i)

        #print(D)

        for x in D:
            LIST[x%9]+=D[x]

        if LIST[0]>0:
            continue

        #print(LIST)
        X=1
        for j in range(9):
            X=X*pow(j,LIST[j],9)%9

        ANS=(ANS+S[i]*X)%9

    if ANS==0:
        ANS=9

    print(ANS)
        
        
        
        
    
        
0