結果

問題 No.171 スワップ文字列(Med)
ユーザー tentententen
提出日時 2021-11-10 16:08:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 2,465 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 78,900 KB
実行使用メモリ 50,376 KB
最終ジャッジ日時 2024-05-01 03:38:06
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,372 KB
testcase_01 AC 51 ms
49,848 KB
testcase_02 AC 55 ms
50,148 KB
testcase_03 AC 50 ms
50,112 KB
testcase_04 AC 51 ms
50,276 KB
testcase_05 AC 54 ms
50,136 KB
testcase_06 AC 55 ms
50,360 KB
testcase_07 AC 57 ms
50,204 KB
testcase_08 AC 58 ms
50,288 KB
testcase_09 AC 57 ms
50,376 KB
testcase_10 AC 53 ms
50,232 KB
testcase_11 AC 51 ms
50,280 KB
testcase_12 AC 50 ms
50,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 573;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int[] counts = new int[26];
        int total = 0;
        for (char c : sc.next().toCharArray()) {
            total++;
            counts[c - 'A']++;
        }
        HashMap<Integer, Integer> all = new HashMap<>();
        for (int i = 2; i <= total; i++) {
            int x = i;
            for (int j = 2; j <= Math.sqrt(x); j++) {
                while (x % j == 0) {
                    all.put(j, all.getOrDefault(j, 0) + 1);
                    x /= j;
                }
            }
            if (x > 1) {
                all.put(x, all.getOrDefault(x, 0) + 1);
            }
        }
        for (int x : counts) {
            for (int i = 2; i <= x; i++) {
                int y = i;
                for (int j = 2; j <= Math.sqrt(y); j++) {
                    while (y % j == 0) {
                        all.put(j, all.get(j) - 1);
                        y /= j;
                    }
                }
                if (y > 1) {
                    all.put(y, all.get(y) - 1);
                }
            }
        }
        long ans = 1;
        for (int x : all.keySet()) {
            ans *= pow(x, all.get(x));
            ans %= MOD;
        }
        ans = (ans - 1 + MOD) % MOD;
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}
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