結果
問題 |
No.171 スワップ文字列(Med)
|
ユーザー |
![]() |
提出日時 | 2021-11-10 16:08:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 60 ms / 1,000 ms |
コード長 | 2,465 bytes |
コンパイル時間 | 2,500 ms |
コンパイル使用メモリ | 78,856 KB |
実行使用メモリ | 37,152 KB |
最終ジャッジ日時 | 2024-11-21 04:04:23 |
合計ジャッジ時間 | 3,741 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
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(); } }