結果
問題 | No.294 SuperFizzBuzz |
ユーザー |
|
提出日時 | 2017-02-03 10:15:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 174 ms / 5,000 ms |
コード長 | 1,242 bytes |
コンパイル時間 | 2,238 ms |
コンパイル使用メモリ | 78,072 KB |
実行使用メモリ | 41,620 KB |
最終ジャッジ日時 | 2024-12-24 04:06:43 |
合計ジャッジ時間 | 5,467 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);long[][] nCk = new long[26][26];nCk[0][0] = 1;for (int i = 1; i <= 25; ++i) {for (int j = 0; j <= i; ++j) {nCk[i][j] = (j > 0 ? nCk[i - 1][j - 1] : 0) + (i - 1 >= j ? nCk[i - 1][j] : 0);}}long[] count = new long[26];// count[i]:i桁の時の組み合わせの数for (int i = 1; i < count.length; ++i) {count[i] = count[i - 1];for (int j = 3; j <= i; j += 3) {count[i] += nCk[i - 1][j - 1];}}int N = sc.nextInt();int digit = 0;while (count[digit] < N)++digit;long cnt = N - count[digit - 1];for (int i = 1; i < (1 << digit); i += 2) {int c5 = Integer.bitCount(i);if (c5 % 3 == 0) {--cnt;}if (cnt == 0) {for (int j = digit - 1; j >= 0; --j) {if (((1 << j) & i) > 0) {System.out.print(5);} else {System.out.print(3);}}System.out.println();return;}}tr(count[digit]);tr(count);}static void tr(Object... objects) {System.out.println(Arrays.deepToString(objects));}}