結果

問題 No.1529 Constant Lcm
ユーザー 👑 potato167potato167
提出日時 2021-06-04 20:30:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,508 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 213,824 KB
実行使用メモリ 11,996 KB
最終ジャッジ日時 2023-08-12 09:37:03
合計ジャッジ時間 27,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 6 ms
4,384 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 1,999 ms
11,160 KB
testcase_11 AC 780 ms
6,224 KB
testcase_12 AC 42 ms
4,380 KB
testcase_13 AC 1,694 ms
9,904 KB
testcase_14 AC 1,101 ms
7,872 KB
testcase_15 AC 1,160 ms
7,816 KB
testcase_16 AC 890 ms
7,032 KB
testcase_17 AC 488 ms
5,176 KB
testcase_18 AC 531 ms
5,332 KB
testcase_19 AC 1,121 ms
7,780 KB
testcase_20 AC 2,188 ms
11,996 KB
testcase_21 AC 2,184 ms
11,820 KB
testcase_22 AC 2,182 ms
11,956 KB
testcase_23 AC 2,199 ms
11,892 KB
testcase_24 AC 2,198 ms
11,984 KB
testcase_25 AC 2,185 ms
11,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}


//a以下の素数を列挙、計算量:Nlog(log(N))
vector<long long> Eratosthenes(long long a){
    if(a<2) return {};
    vector<long long> p(a+1),ans;
    p[0]=1,p[1]=1;
    long long k=2;
    while(k*k<=a){
        if(p[k]==0){
            ans.push_back(k);
            for(long long i=2;i*k<=a;i++){
                p[i*k]=1;
            }
        }
        k++;
    }
    while(k<=a){
        if(p[k]==0) ans.push_back(k);
        k++;
    }
    return ans;
}


//Nの正の約数を列挙する
vector<long long> Divisors(long long N){
    vector<long long> p,q;
    long long i=1,K=0;
    while(i*i<N){
        if(N%i==0){
            p.push_back(i);
            q.push_back(N/i);
            K++;
        }
        i++;
    }
    if(i*i==N) p.push_back(i);
    for(int i=K-1;i>=0;i--){
        p.push_back(q[i]);
    }
    return p;
}

//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;

	int D=1100;
	auto p=Eratosthenes(N-1);
	int M=p.size();
	map<int,int> m;
	rep(i,M){
		m[p[i]]=i;
	}
	int ans[M]={0};
	rep(i,(N+4)/2){
		int A=i+1,B=N-1-i;
		int k=0;
		while(p[k]<D){
			int X=0;
			while(A%p[k]==0){
				X++;
				A/=p[k];
			}
			while(B%p[k]==0){
				X++;
				B/=p[k];
			}
			chmax(ans[k],X);
			k++;
		}
		if(A==1&&B==1) continue;
		if(A==B) chmax(ans[m[A]],2);
		else{
			chmax(ans[m[A]],1);
			chmax(ans[m[B]],1);
		}
	}
	ll Z=1;
	rep(i,M){
		rep(j,ans[i]) Z*=p[i],Z%=Q;
	}
	cout<<Z<<"\n";
	return 0;
}
0