結果

問題 No.294 SuperFizzBuzz
ユーザー cielciel
提出日時 2020-02-08 21:50:24
言語 Crystal
(1.11.2)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 20,983 ms
コンパイル使用メモリ 283,500 KB
実行使用メモリ 4,624 KB
最終ジャッジ日時 2023-09-13 10:17:43
合計ジャッジ時間 22,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,476 KB
testcase_01 AC 2 ms
4,488 KB
testcase_02 AC 46 ms
4,520 KB
testcase_03 AC 3 ms
4,508 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,512 KB
testcase_08 AC 4 ms
4,440 KB
testcase_09 AC 30 ms
4,480 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 38 ms
4,624 KB
testcase_12 AC 42 ms
4,384 KB
testcase_13 AC 44 ms
4,520 KB
testcase_14 AC 47 ms
4,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def comb(n,r)
	if r==0
		return 1_i64
	end
	ret=1_i64
	if r>n//2
		r=n-r
	end
	r.times{|i|
		ret=ret*(n-i)//(i+1)
	}
	return ret
end
def popcnt32(n)
	m1=0x55555555
	m2=0x33333333
	m4=0x0f0f0f0f
	m8=0x00ff00ff
	m16=0x0000ffff
	n=((n>>1)&m1)+(n&m1)
	n=((n>>2)&m2)+(n&m2)
	n=((n>>4)&m4)+(n&m4)
	n=((n>>8)&m8)+(n&m8)
	n=((n>>16)&m16)+(n&m16)
	return n
end

n=gets.not_nil!.to_i
digits=2
loop{
	s=0
	five=2
	while five<=digits
		s+=comb(digits,five)
		five+=3
	end
	break if n<=s
	n-=s
	digits+=1
}
(1..1/0.0).each{|i|
	if popcnt32(i)%3==2
		n-=1
		if n==0
			puts sprintf("%0"+digits.to_s+"b",i).tr("01","35")+"5"
			exit
		end
	end
}
0