結果
問題 | No.1747 Many Formulae 2 |
ユーザー |
|
提出日時 | 2021-11-20 18:24:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,881 bytes |
コンパイル時間 | 4,765 ms |
コンパイル使用メモリ | 208,808 KB |
最終ジャッジ日時 | 2025-01-25 22:14:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long int ; using ld = long double ; using P = pair<ll,ll>; using Graph= vector<vector<ll>>; struct edge{ll to ; ll cost ;} ; using graph =vector<vector<edge>> ; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplace_back #define ppb pop_back #define mpa make_pair #define fi first #define se second #define set20 cout<<fixed<<setprecision(20) ; const ll INF=1e18 ; inline void chmax(ll& a,ll b){a=max(a,b);} inline void chmin(ll& a,ll b){a=min(a,b);} long double pi=acos(-1) ; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} ll dx[4] {1,0,-1,0} ; ll dy[4] {0,1,0,-1} ; #define debug cout<<888<<endl ; // sum(x) x以下の和 // sum(a,b) a以上b以下の和 template<typename T> struct BIT { int n; vector<T> d; BIT(int n=0):n(n),d(n+1) {} void add(int i, T x=1) { //x=1ならsumは個数のカウント for (i++; i <= n; i += i&-i) { d[i] += x; } } T sum(int i) { T x = 0; for (i++; i; i -= i&-i) { x += d[i]; } return x; } T sum(int i,int j) { if(i>0) return sum(j)-sum(i-1); else return sum(j) ; } }; int main(){ ios::sync_with_stdio(false) ; cin.tie(nullptr) ; string s ;cin>>s ; ll k=s.size() ; ll bns=0ll ; rep(i,1<<(k-1)){ bitset<10> ss(i) ; ll ans=0ll ; ll now=s[0]-'0' ; rep(j,k-1){ if(ss[j]){ ans+=now ; now=0ll ; } now*=10 ; ll a=s[j+1]-'0' ; now+=a ; } ans+=now ; bool ok=0 ; //cout<<ans<<endl; if(ans==1) continue ; for(ll j=2;j*j<=ans;++j){ if(ans%j==0) ok=1 ; } if(!ok) bns++ ; } cout<<bns<<endl ; return 0 ; }