結果

問題 No.1747 Many Formulae 2
コンテスト
ユーザー umezo
提出日時 2021-11-20 01:20:22
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 968µs
コード長 728 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,530 ms
コンパイル使用メモリ 217,880 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-10-20 03:15:47
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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