結果

問題 No.1747 Many Formulae 2
ユーザー Kome_soudouKome_soudou
提出日時 2022-05-02 00:59:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 167,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 18:42:13
合計ジャッジ時間 3,002 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<int> checkv(int bit, int N)
{
  vector<int> v(N);
  for(int i = 0; i < N; i++) if(bit & (1 << i)) v[i] = 1;
  
  return v;
}

int main()
{
	string S;
	cin >> S;
	int s = (int)S.size();
	
	if(s == 1)
	{
		if(S == "2" || S == "3" || S == "5" || S == "7") cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	
	int64_t ans = 0;
	int64_t n;
	int64_t T;
	bool pos;
	for(int bit = 0; bit < (1 << (s - 1)); bit++)
	{
		vector<int> C = checkv(bit, s - 1);
		
		n = 0;
		T = 0;
		for(int i = 0; i < s - 1; i++)
		{
			n *= 10;
			n += (int64_t)(S[i] - '0');
			if(C[i] == 1)
			{
				T += n;
				n = 0;
			}
		}
		n *= 10;
		n += (int64_t)(S[s - 1] - '0');
		T += n;
		
		pos = true;
		for(int64_t i = 2; i * i <= T; i++)
		{
			if(T % i == 0)
			{
				pos = false;
				break;
			}
		}
		if(pos) ans++;
	}
	cout << ans << endl;
	return 0;
}
0