結果

問題 No.294 SuperFizzBuzz
コンテスト
ユーザー roiti46
提出日時 2015-12-09 20:01:06
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 252 ms / 5,000 ms
コード長 1,110 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 111 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 95,872 KB
最終ジャッジ日時 2026-04-04 17:45:36
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def comb(n, r):
    res = 1
    for i in xrange(r):
        res *= n - i
    for i in xrange(1, r + 1):
        res /= i
    return res

def bitcount(x):
    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)

ans = 0
N = int(raw_input())
#3は5n個、5は3m個。1桁目は必ず5
for k in xrange(3, 26):
    cnt = 0
    for i in xrange(3, k + 1, 3):
        j = k - i
        cnt += comb(j + i - 1, i - 1)
    if N > cnt:
        N -= cnt
    else:
        x = -1
        while N:
            x += 2
            if bitcount(x) % 3 == 0: N -= 1
        ans = bin(x)[2:].zfill(k).replace("0", "3").replace("1", "5")
        break
    if ans > 0: break
print ans
0