結果

問題 No.2972 確率的素数判定
コンテスト
ユーザー eQe
提出日時 2026-10-24 04:39:50
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 65 ms / 2,000 ms
+ 112µs
コード長 3,298 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,614 ms
コンパイル使用メモリ 340,544 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-10-24 04:39:59
合計ジャッジ時間 7,004 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/*
#include<kyopro/master>
void self::main(){
  ll M=1e5;
  auto primes=prime_enumerate(M);
  
  LL(T);
  FO(T){
    LL(N);
    DD(P,Q);
    P/=100,Q/=100;
    
    ll c=primes.le_count(N);
    dd PAB=P*c/N;
    dd PA=P*c/N+(1-Q)*(N-c)/N;
    pp(PAB/PA);
  }
  
  
  
}
*/

#include<bits/stdc++.h>
using namespace std;
namespace self{void main();void sub();template<ostream&o>void pp(const auto&...a);void epp(const auto&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define eb emplace_back
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define DD(...) RD(dd,__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define of(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(1,__VA_ARGS__);i>=i##stop;i+=i##step)
namespace self{
using dd=double;
using ll=long long;
using ui32=uint32_t;
using ui64=uint64_t;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
constexpr ui64 kth_root_floor(ui64 a,ll k){
  if (k==1)return a;
  auto within=[&](ui32 x){ui64 t=1;FO(k)if(__builtin_mul_overflow(t,x,&t))return false;return t<=a;};

  ui64 r=0;
  of(i,sizeof(ui32)*CHAR_BIT)if(within(r|(1u<<i)))r|=1u<<i;
  return r;
}
constexpr auto sqrt_floor(auto x){return kth_root_floor(x,2);}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
template<class I>class Iterator{
private:
  I it_,begin_,end_;
public:
  Iterator(I it,I begin,I end):it_(it),begin_(begin),end_(end){}
  ll dist()const{return it_-begin_;}
};
}
namespace self{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  using vector<V>::vector;
  ll size()const{return vector<V>::size();}
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
  auto pop_back(){auto r=this->back();vector<V>::pop_back();return r;}
  auto first_true(const V&x,auto&&f)const{
    auto b=this->begin(),e=this->end();
    auto p=partition_point(b,e,[&x,&f](const V&v){return !f(x,v);});
    return Iterator{p,b,e};
  }
  auto first_gt(const V&x)const{return first_true(x,[](auto&x,auto&e){return x<e;});}
  ll le_count(const V&x)const{return first_gt(x).dist();}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace self{
auto prime_enumerate(ll n){
  vec<bool>sieve(n/3+1,1);
  for(ll p=5,d=4,i=1,rn=sqrt_floor(n);p<=rn;p+=d=6-d,i++){
    if(!sieve[i])continue;
    for(ll q=(p*p)/3,r=d*p/3+(d*p%3==2),s=p*2;q<sieve.size();q+=r=s-r)sieve[q]=0;
  }
  vec<ll>r{2,3};
  for(ll p=5,d=4,i=1;p<=n;p+=d=6-d,i++)if(sieve[i])r.eb(p);
  while(r.size()&&r.back()>n)r.pop_back();
  return r;
}
}
template<ostream&o=cout>void self::pp(const auto&...a){const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}
void self::main(){
  ll M=1e5;
  auto primes=prime_enumerate(M);

  LL(T);
  FO(T){
    LL(N);
    DD(P,Q);
    P/=100,Q/=100;

    ll c=primes.le_count(N);
    dd PAB=P*c/N;
    dd PA=P*c/N+(1-Q)*(N-c)/N;
    pp(PAB/PA);
  }

}
0