結果

問題 No.1747 Many Formulae 2
ユーザー ks2mks2m
提出日時 2021-11-19 21:34:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 74,856 KB
実行使用メモリ 55,996 KB
最終ジャッジ日時 2023-08-30 07:35:53
合計ジャッジ時間 5,734 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,588 KB
testcase_01 AC 120 ms
55,912 KB
testcase_02 AC 121 ms
55,560 KB
testcase_03 AC 120 ms
55,492 KB
testcase_04 AC 120 ms
55,924 KB
testcase_05 AC 120 ms
55,792 KB
testcase_06 AC 122 ms
55,996 KB
testcase_07 AC 121 ms
55,504 KB
testcase_08 AC 121 ms
55,508 KB
testcase_09 AC 121 ms
55,732 KB
testcase_10 AC 120 ms
55,608 KB
testcase_11 AC 121 ms
55,660 KB
testcase_12 AC 122 ms
55,800 KB
testcase_13 AC 121 ms
55,688 KB
testcase_14 AC 121 ms
55,356 KB
testcase_15 AC 122 ms
55,732 KB
testcase_16 AC 123 ms
55,960 KB
testcase_17 AC 124 ms
55,644 KB
testcase_18 AC 120 ms
55,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int ans = 0;
		int n = s.length - 1;
		int end = 1 << n;
		for (int i = 0; i < end; i++) {
			long val = 0;
			long now = s[0] - '0';
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					val += now;
					now = s[j + 1] - '0';
				} else {
					now *= 10;
					now += s[j + 1] - '0';
				}
			}
			val += now;
			if (isSosuu(val)) {
				ans++;
			}
		}
		System.out.println(ans);
	}

	static boolean isSosuu(long n) {
		if (n < 2) return false;
		if (n == 2) return true;
		long end = (int) Math.sqrt(n) + 1;
		for (int i = 2; i <= end; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}
0