結果

問題 No.294 SuperFizzBuzz
ユーザー しらっ亭しらっ亭
提出日時 2015-10-24 00:51:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 245 ms / 5,000 ms
コード長 1,335 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 76,224 KB
最終ジャッジ日時 2023-10-11 05:15:02
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,548 KB
testcase_01 AC 75 ms
71,124 KB
testcase_02 AC 244 ms
76,224 KB
testcase_03 AC 74 ms
71,320 KB
testcase_04 AC 73 ms
71,252 KB
testcase_05 AC 73 ms
71,320 KB
testcase_06 AC 75 ms
71,304 KB
testcase_07 AC 81 ms
75,996 KB
testcase_08 AC 87 ms
76,080 KB
testcase_09 AC 185 ms
75,984 KB
testcase_10 AC 75 ms
71,316 KB
testcase_11 AC 216 ms
75,884 KB
testcase_12 AC 227 ms
75,964 KB
testcase_13 AC 236 ms
75,880 KB
testcase_14 AC 245 ms
75,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


def combi(n, mod):
    c = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for x in range(n + 1):
        c[x][0] = 1
        for y in range(1, x + 1):
            c[x][y] = (c[x - 1][y] + c[x - 1][y - 1]) % mod
    return c


def bitcount(x):
    """
    立っているbitの数
    """
    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f)
    x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff)
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
    return (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)


def out(n, m):
    # n 桁の m 番目
    x = 0
    for i in range((1 << n) + 1):
        if bitcount(i) % 3 == 2:
            x += 1
            if x == m:
                b = bin(i)[2:]
                b = b.replace('0', '3').replace('1', '5')
                print('3' * (n - len(b)) + b, '5', sep='')
                return


def solve():
    N = int(input())

    co = combi(26, 10000007)

    i = 0
    for n in count(2):
        j = i
        for r in range(n - 2, -1, -3):
            i += co[n][r]
        if i >= N:
            out(n, N - j)
            return


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