結果

問題 No.294 SuperFizzBuzz
ユーザー tentententen
提出日時 2021-11-11 12:51:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,556 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 79,676 KB
実行使用メモリ 38,588 KB
最終ジャッジ日時 2024-05-02 05:58:24
合計ジャッジ時間 6,005 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,096 KB
testcase_01 AC 53 ms
37,520 KB
testcase_02 AC 466 ms
38,356 KB
testcase_03 WA -
testcase_04 AC 53 ms
37,276 KB
testcase_05 WA -
testcase_06 AC 54 ms
37,776 KB
testcase_07 AC 54 ms
37,904 KB
testcase_08 AC 88 ms
38,588 KB
testcase_09 AC 331 ms
38,400 KB
testcase_10 WA -
testcase_11 AC 391 ms
38,396 KB
testcase_12 AC 445 ms
38,392 KB
testcase_13 AC 448 ms
38,396 KB
testcase_14 AC 463 ms
38,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static long[][] comb = new long[200][200];
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextInt() - 1;
        for (int i = 0; i < 200; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    comb[i][j] = 1;
                } else {
                    comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
                }
            }
        }
        int count = 2;
        while (true) {
            long sum = getSum(count);
            if (n <= sum) {
                break;
            }
            n -= sum;
            count++;
        }
        System.out.println(getString(count, n + 1) + "5");
    }
    
    static long getSum(int count) {
        long sum = 0;
        for (int i = 0; i * 3 + 2 <= count; i++) {
            sum += getSum(count, i * 3 + 2);
        }
        return sum;
    }
    
    static long getSum(int all, int part) {
        return comb[all][part];
    }
    
    static String getString(int count, long size) {
        int mask = 0;
        for (int i = 0; i < size; i++) {
            mask++;
            while (getPop(mask) % 3 < 2) {
                mask++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++) {
            if (mask % 2 == 0) {
                sb.append("3");
            } else {
                sb.append("5");
            }
            mask >>= 1;
        }
        return sb.reverse().toString();
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x /= 2;
        }
        return pop;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0