結果

問題 No.1529 Constant Lcm
ユーザー 👑 potato167potato167
提出日時 2021-06-04 20:38:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,195 ms / 3,000 ms
コード長 2,591 bytes
コンパイル時間 2,683 ms
コンパイル使用メモリ 212,792 KB
実行使用メモリ 12,124 KB
最終ジャッジ日時 2023-08-12 09:53:34
合計ジャッジ時間 26,720 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,976 KB
testcase_01 AC 36 ms
11,864 KB
testcase_02 AC 31 ms
11,984 KB
testcase_03 AC 31 ms
11,864 KB
testcase_04 AC 30 ms
11,976 KB
testcase_05 AC 32 ms
11,984 KB
testcase_06 AC 31 ms
11,976 KB
testcase_07 AC 32 ms
11,860 KB
testcase_08 AC 31 ms
11,872 KB
testcase_09 AC 31 ms
11,888 KB
testcase_10 AC 1,974 ms
11,860 KB
testcase_11 AC 794 ms
11,972 KB
testcase_12 AC 72 ms
11,916 KB
testcase_13 AC 1,708 ms
11,968 KB
testcase_14 AC 1,094 ms
11,932 KB
testcase_15 AC 1,169 ms
11,976 KB
testcase_16 AC 914 ms
12,116 KB
testcase_17 AC 519 ms
12,124 KB
testcase_18 AC 550 ms
11,920 KB
testcase_19 AC 1,128 ms
11,980 KB
testcase_20 AC 2,167 ms
11,916 KB
testcase_21 AC 2,194 ms
11,924 KB
testcase_22 AC 2,169 ms
11,976 KB
testcase_23 AC 2,187 ms
11,964 KB
testcase_24 AC 2,195 ms
12,076 KB
testcase_25 AC 2,177 ms
11,968 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(1000000);
	int M=p.size();
	map<int,int> m;
	rep(i,M){
		m[p[i]]=i;
	}
	int ans[M]={0};
	rep(i,M) ans[i]=0;

	rep(i,N-1){
		int A=i+1,B=N-1-i;
		int k=0;
		if(A>B) break;
		//cout<<A<<" "<<B<<endl;
		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{
			if(A!=1) chmax(ans[m[A]],1);
			if(B!=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