結果
問題 | No.1747 Many Formulae 2 |
ユーザー |
![]() |
提出日時 | 2021-11-22 09:45:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,630 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 78,064 KB |
実行使用メモリ | 50,500 KB |
最終ジャッジ日時 | 2024-06-23 19:26:40 |
合計ジャッジ時間 | 4,091 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.io.*; import java.util.*; public class Main { static int count; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); makeAns(0, sc.next().toCharArray(), 0, 0); System.out.println(count); } static void makeAns(int idx, char[] string, long value, long total) { if (idx >= string.length) { if (isPrime(value + total)) { count++; } return; } makeAns(idx + 1, string, string[idx] - '0', value + total); if (idx > 0) { makeAns(idx + 1, string, value * 10 + string[idx] - '0', total); } } static boolean isPrime(long x) { if (x < 2) { return false; } for (long i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } } 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 next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }