結果

問題 No.1747 Many Formulae 2
ユーザー umezoumezo
提出日時 2021-11-20 01:20:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 205,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 14:10:48
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

bool isPrime(ll x){
  if(x<2) return false;
  else if(x==2) return true;
  if(x%2==0) return false;
  for(ll i=3;i*i<=x;i+=2){
    if(x%i==0) return false;
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  string s;
  cin>>s;
  int n=s.size();
  map<ll,ll> m;
  for(int bit=0;bit<(1<<(n-1));bit++){
    ll sum=0;
    ll t=1;
    rep(i,n){
      sum+=(s[n-1-i]-'0')*t;
      if(bit&(1<<i)) t=1;
      else t*=10;
    }
    m[sum]++;
  }
  ll ans=0;
  for(auto [a,b]:m){
    if(isPrime(a)) ans+=b;
  }
  cout<<ans<<endl;
  
  return 0;
}
0