結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tko919tko919
提出日時 2021-08-27 21:23:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 907 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 201,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 07:47:13
合計ジャッジ時間 7,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 769 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 696 ms
4,380 KB
testcase_13 AC 299 ms
4,376 KB
testcase_14 AC 334 ms
4,380 KB
testcase_15 AC 448 ms
4,380 KB
testcase_16 AC 129 ms
4,376 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 57 ms
4,376 KB
testcase_19 AC 785 ms
4,376 KB
testcase_20 AC 192 ms
4,380 KB
testcase_21 AC 907 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 77 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

bool Miller(ll n){
   if(n<2 or (n&1)==0)return (n==2);
   ll d=n-1; while((d&1)==0)d>>=1;
   vector<ll> seeds;
   auto MP=[&](ll x,ll t,ll m)->ll{
      ll res=1;
      while(t){
         if(t&1)res=(__int128_t(res)*x)%m;
         x=(__int128_t(x)*x)%m; t>>=1;
      } return res;
   };
   if(n<(1<<30))seeds={2, 7, 61};
   else seeds={2, 325, 9375, 28178, 450775, 9780504};
   for(auto& x:seeds){
      if(n<=x)break;
      ll t=d,y=MP(x,t,n);
      while(t!=n-1 and y!=1 and y!=n-1){
         y=(__int128_t(y)*y)%n; t<<=1;
      }
      if(y!=n-1 and (t&1)==0)return 0;
   } return 1;
}

int main(){
   int L,R;
   cin>>L>>R;

   int res=0;
   rep(a,L,R+1){
      if(Miller(a))res++;
      if(a!=R and Miller(a*2+1))res++;
   }
   cout<<res<<'\n';
   return 0;
}
0