結果

問題 No.2752 文字列の数え上げ mod 998244353
ユーザー hato336hato336
提出日時 2024-05-10 21:35:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 2,396 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 76,616 KB
最終ジャッジ日時 2024-05-10 21:36:01
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,156 KB
testcase_01 AC 37 ms
54,196 KB
testcase_02 AC 42 ms
52,924 KB
testcase_03 AC 36 ms
52,340 KB
testcase_04 AC 37 ms
52,960 KB
testcase_05 AC 37 ms
53,340 KB
testcase_06 AC 38 ms
54,324 KB
testcase_07 AC 37 ms
53,128 KB
testcase_08 AC 37 ms
53,592 KB
testcase_09 AC 37 ms
54,324 KB
testcase_10 AC 37 ms
54,332 KB
testcase_11 AC 37 ms
53,760 KB
testcase_12 AC 37 ms
53,080 KB
testcase_13 AC 37 ms
53,544 KB
testcase_14 AC 37 ms
52,772 KB
testcase_15 AC 37 ms
53,336 KB
testcase_16 AC 36 ms
52,864 KB
testcase_17 AC 37 ms
52,836 KB
testcase_18 AC 37 ms
53,332 KB
testcase_19 AC 38 ms
53,948 KB
testcase_20 AC 128 ms
76,184 KB
testcase_21 AC 180 ms
76,020 KB
testcase_22 AC 188 ms
76,616 KB
testcase_23 AC 185 ms
76,304 KB
testcase_24 AC 155 ms
76,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    while a:
        a, b = b%a, a
    return b


def is_prime(n):
    if n == 2:
        return 1
    if n == 1 or n%2 == 0:
        return 0

    m = n - 1
    lsb = m & -m
    s = lsb.bit_length()-1
    d = m // lsb

    test_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]

    for a in test_numbers:
        if a == n:
            continue
        x = pow(a,d,n)
        r = 0
        if x == 1:
            continue
        while x != m:
            x = pow(x,2,n)
            r += 1
            if x == 1 or r == s:
                return 0
    return 1


def find_prime_factor(n):
    if n%2 == 0:
        return 2

    m = int(n**0.125)+1

    for c in range(1,n):
        f = lambda a: (pow(a,2,n)+c)%n
        y = 0
        g = q = r = 1
        k = 0
        while g == 1:
            x = y
            while k < 3*r//4:
                y = f(y)
                k += 1
            while k < r and g == 1:
                ys = y
                for _ in range(min(m, r-k)):
                    y = f(y)
                    q = q*abs(x-y)%n
                g = gcd(q,n)
                k += m
            k = r
            r *= 2
        if g == n:
            g = 1
            y = ys
            while g == 1:
                y = f(y)
                g = gcd(abs(x-y),n)
        if g == n:
            continue
        if is_prime(g):
            return g
        elif is_prime(n//g):
            return n//g
        else:
            return find_prime_factor(g)


def factorize(n):
    res = {}
    while not is_prime(n) and n > 1:  # nが合成数である間nの素因数の探索を繰り返す
        p = find_prime_factor(n)
        s = 0
        while n%p == 0:  # nが素因数pで割れる間割り続け、出力に追加
            n //= p
            s += 1
        res[p] = s
    if n > 1:  # n>1であればnは素数なので出力に追加
        res[n] = 1
    return res

import sys
input = sys.stdin.readline
q = int(input())
x = []
a = 26
mod = 998244353
x.append(a)
c = 26
clist = [26]
for i in range(61):
    x.append(x[-1] + x[-1] * c)
    x[-1] %= mod
    c = (c * c) % mod
    clist.append(c)

for i in range(q):
    l = int(input())
    ans = 0
    temp = 1
    for j in range(60):
        if(l >> j) & 1 == 1:
            ans += x[j] * temp
            temp *= clist[j]
            ans %= mod
            temp %= mod
    print(ans)
0