結果

問題 No.294 SuperFizzBuzz
ユーザー tentententen
提出日時 2023-06-13 16:17:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 973 ms / 5,000 ms
コード長 2,307 bytes
コンパイル時間 4,127 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 34,836 KB
最終ジャッジ日時 2023-09-04 01:29:46
合計ジャッジ時間 11,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
33,752 KB
testcase_01 AC 40 ms
33,504 KB
testcase_02 AC 973 ms
34,480 KB
testcase_03 AC 41 ms
33,396 KB
testcase_04 AC 39 ms
33,848 KB
testcase_05 AC 40 ms
33,396 KB
testcase_06 AC 40 ms
33,724 KB
testcase_07 AC 43 ms
33,480 KB
testcase_08 AC 97 ms
34,200 KB
testcase_09 AC 552 ms
34,428 KB
testcase_10 AC 551 ms
34,428 KB
testcase_11 AC 892 ms
34,528 KB
testcase_12 AC 927 ms
34,396 KB
testcase_13 AC 953 ms
34,836 KB
testcase_14 AC 971 ms
34,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        for (int i = 2; ; i++) {
            for (int k = 1; k < (1 << i); k++) {
                if (getPop(k) % 3 == 2) {
                    n--;
                    if (n == 0) {
                        System.out.println(getNumber(k, i));
                        return;
                    }
                }
            }
        }
    }
    
    static String getNumber(int mask, int size) {
        StringBuilder sb = new StringBuilder("5");
        for (int i = 0; i < size; 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 >>= 1;
        }
        return pop;
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0