結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー |
![]() |
提出日時 | 2021-08-27 21:23:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 894 ms / 2,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 1,913 ms |
コンパイル使用メモリ | 196,556 KB |
最終ジャッジ日時 | 2025-01-24 02:26:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#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; }