結果

問題 No.294 SuperFizzBuzz
ユーザー cielciel
提出日時 2015-10-24 01:52:49
言語 Crystal
(1.11.2)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 22,693 ms
コンパイル使用メモリ 284,120 KB
実行使用メモリ 4,616 KB
最終ジャッジ日時 2023-09-13 08:58:45
合計ジャッジ時間 23,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,500 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 49 ms
4,480 KB
testcase_03 AC 2 ms
4,416 KB
testcase_04 AC 3 ms
4,616 KB
testcase_05 AC 2 ms
4,500 KB
testcase_06 AC 3 ms
4,452 KB
testcase_07 AC 3 ms
4,592 KB
testcase_08 AC 5 ms
4,520 KB
testcase_09 AC 33 ms
4,492 KB
testcase_10 AC 3 ms
4,508 KB
testcase_11 AC 42 ms
4,556 KB
testcase_12 AC 45 ms
4,408 KB
testcase_13 AC 47 ms
4,508 KB
testcase_14 AC 50 ms
4,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal
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