結果

問題 No.2972 確率的素数判定
ユーザー twooimp2
提出日時 2024-12-29 19:17:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 5,299 ms
コンパイル使用メモリ 267,232 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 19:17:46
合計ジャッジ時間 7,678 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout<<fixed<<setprecision(10);
}

int main(){
  IO();
  ll t;
  cin>>t;
  vector<ll> prime;
  vector<bool> seen(100000,false);
  for(ll i=2;i<100000;i++){
    if(!seen[i]){
      seen[i]=true;
      prime.emplace_back(i);
      for(ll j=2*i;j<100000;j+=i){
        seen[j]=true;
      }
    }
  }
  while(t--){
    ll n,p,q;
    cin>>n>>p>>q;
    auto itr=lower_bound(prime.begin(),prime.end(),n);
    if(*itr==n){
      ld cp=itr-prime.begin()+1;
      ld bunshi=cp*p;
      ld bunbo=cp*(p+q)+100*(n-cp)-n*q;
      cout<<bunshi/bunbo<<endl;
    }else if(itr!=prime.begin()){
      itr--;
      ld cp=itr-prime.begin()+1;
      ld bunshi=cp*p;
      ld bunbo=cp*(p+q)+100*(n-cp)-n*q;
      cout<<bunshi/bunbo<<endl;
    }else if(itr==prime.begin()){
      cout<<0<<endl;
    }
  }
}
0