結果

問題 No.1747 Many Formulae 2
ユーザー umezo
提出日時 2021-11-20 01:20:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 199,680 KB
最終ジャッジ日時 2025-01-25 21:20:19
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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