結果

問題 No.36 素数が嫌い!
ユーザー hiro1729hiro1729
提出日時 2023-09-10 20:01:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,992 bytes
コンパイル時間 8,726 ms
コンパイル使用メモリ 349,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 20:01:39
合計ジャッジ時間 10,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ll _findprime(ll)’ 内:
main.cpp:75:276: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   75 | ll _findprime(ll n){if(n%2==0)return 2;for(int c=1;c<n;c++){auto f=[&](ll a)->ll {return((bll)a*a+c)%n;};ll x=0,y=0,g=1;while(g==1){x=f(x);y=f(f(y));g=gcd(abs(x-y),n);}if(g==n)continue;if(MillerRabin(g))return g;else if(MillerRabin(n/g))return n/g;else return _findprime(g);}}
      |                                                                                                                                                                                                                                                                                    ^

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#if __has_include(<bits/stdc++.h>)
#include <bits/stdc++.h>
#else
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <numeric>
#include <iomanip>
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define rvrep(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(auto i:v)
#define all(x) x.begin(),x.end()
template<typename T>inline bool chmax(T &a,T b){return((a<b)?(a=b,true):(false));}
template<typename T>inline bool chmin(T &a,T b){return((a>b)?(a=b,true):(false));}
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using pii=pair<int,int>;using vpii=vector<pii>;using pll=pair<ll,ll>;using vpll=vector<pll>;using pli=pair<ll,int>;using pil=pair<int,ll>;
using mpi=map<int,int>;using mps=map<string,int>;using mpc=map<char,int>;using mpl=map<ll,int>;
using sti=set<int>;using stc=set<char>;using sts=set<string>;using stl=set<ll>;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353;
using mint1=modint1000000007;
#endif

using bll = __int128_t;

// O(√n) verified
bool is_prime(ll n){if(n<2)return false;if(n==2)return true;if(n%2==0)return false;for(ll i=3;i*i<=n;i+=2)if(n%i==0)return false;return true;}

// O(√n) verified
vector<ll>divisors(ll n){vector<ll>r;int i;for(i=1;i*i<n;i++)if(n%i==0){r.push_back(i);r.push_back(n/i);}if(i*i==n)r.push_back(i);sort(r.begin(),r.end());return r;}

// O(√n) verified
vector<pair<ll,ll>>prime_factorize(ll n){vector<pair<ll,ll>>r;int c=0;while(n%2==0){n/=2;c++;}r.push_back({2,c});for(ll p=3;p*p<=n;p+=2){if(n%p!=0)continue;int e=0;while(n%p==0){e++;n/=p;}r.push_back({p,e});}if(n!=1)r.push_back({n,1});return r;}

// エラトステネスの篩
// O(n*log(log(n))) verified
vector<bool>EraSieve(ll n){vector<bool>p(n+1,true);p[0]=p[1]=false;for(ll i=2;i*i<=n;i++){if(!p[i])continue;for(int q=i*2;q<=n;q+=i){p[q]=false;}}return p;}

// エラトステネスの区間篩 verified
// a以上b未満のcに対してp[c - a]
vector<bool>EraSecSieve(ll a,ll b){ll sq=(ll)ceil(sqrt(b));vector<bool>ps(sq,true);ps[0]=ps[1]=false;for(ll i=2;i<sq;i++){if(!ps[i])continue;for(ll j=i*i;j<sq;j+=i)ps[j]=false;}vector<bool>p(b-a,true);for(ll i=2;i<sq;i++){if(!ps[i])continue;ll k=max(i,(a+i-1)/i);for(ll j=k*i;j<b;j+=i)p[j-a]=false;}return p;}

// PollardRhoまでverified

template<class T>T modpow(T a,T n,T m){T r=1;while(n){if(n&1)r=r*a%m;a=a*a%m;n>>=1;}return r;}

// 失敗率 1/(4^30)
bool MillerRabin(ll n) {if(n==2)return true;if(n==1||(n>2&&n%2==0))return false;ll s=0,t=n-1;while(t%2==0){s++;t>>=1;}random_device gen;mt19937_64 mtrand(gen());for(int i=0;i<30;i++){ll a=(mtrand())%(n-1)+1;if(a%n==0)continue;bool ok=false;if(modpow<bll>(a,t,n)==1)ok=true;else for(int i=0;i<s;i++)if(modpow<bll>(a,modpow<bll>(2,i,1ull<<63)*t,n)==n-1){ok=true;break;}if(!ok)return false;}return true;}

ll _findprime(ll n){if(n%2==0)return 2;for(int c=1;c<n;c++){auto f=[&](ll a)->ll {return((bll)a*a+c)%n;};ll x=0,y=0,g=1;while(g==1){x=f(x);y=f(f(y));g=gcd(abs(x-y),n);}if(g==n)continue;if(MillerRabin(g))return g;else if(MillerRabin(n/g))return n/g;else return _findprime(g);}}

vector<pair<ll,ll>>PollardRho(ll n){vector<pair<ll,ll>>r;while(!MillerRabin(n)&&n>1){ll p=_findprime(n),s=0;while(n%p==0){n/=p;s++;}r.push_back({p,s});}if(n>1)r.push_back({n,1});return r;}
// memo:PollardRhoからvector<ll>を作った後にsortするのを忘れない

int main() {
	ll n; cin >> n;
	if (n == 1) cout << "NO\n";
	else cout << (MillerRabin(n) ? "NO\n" : "YES\n");
}
0