結果

問題 No.1396 Giri
ユーザー leaf_1415leaf_1415
提出日時 2021-02-14 21:39:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,578 ms / 2,000 ms
コード長 2,289 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 95,992 KB
実行使用メモリ 16,172 KB
最終ジャッジ日時 2023-09-29 14:53:13
合計ジャッジ時間 15,642 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
11,176 KB
testcase_01 AC 11 ms
11,192 KB
testcase_02 AC 1,547 ms
16,096 KB
testcase_03 AC 11 ms
11,212 KB
testcase_04 AC 12 ms
11,212 KB
testcase_05 AC 1,578 ms
16,084 KB
testcase_06 AC 11 ms
11,252 KB
testcase_07 AC 12 ms
11,136 KB
testcase_08 AC 12 ms
11,216 KB
testcase_09 AC 11 ms
11,148 KB
testcase_10 AC 12 ms
11,428 KB
testcase_11 AC 12 ms
11,144 KB
testcase_12 AC 11 ms
11,204 KB
testcase_13 AC 12 ms
11,144 KB
testcase_14 AC 11 ms
11,152 KB
testcase_15 AC 11 ms
11,140 KB
testcase_16 AC 13 ms
11,372 KB
testcase_17 AC 22 ms
11,420 KB
testcase_18 AC 96 ms
11,616 KB
testcase_19 AC 752 ms
13,992 KB
testcase_20 AC 1,076 ms
14,832 KB
testcase_21 AC 1,394 ms
15,652 KB
testcase_22 AC 1,538 ms
15,988 KB
testcase_23 AC 1,553 ms
16,072 KB
testcase_24 AC 1,551 ms
16,036 KB
testcase_25 AC 1,552 ms
16,172 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:91:3: warning: ‘ans_i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(i == ans_i) continue;
   ^~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define outl(x) cout << x << endl
#define SP << " " << 
#define inf 1e18
#define mod 998244353

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

ll n;
ll prime[1000005];
map<ll, P> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	rep(i, 2, 1005){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = i;
	}
	
	cin >> n;
	rep(i, 1, n){
		ll x = i; map<ll, ll> tmp;
		while(prime[x]){
			tmp[prime[x]]++;
			x /= prime[x];
		}
		if(x > 1) tmp[x]++;
		
		for(auto p : tmp){
			P q = mp[p.first];
			chmax(q.second, min(q.first, p.second));
			chmax(q.first, p.second);
			mp[p.first] = q;
		}
	}
	
	//for(auto q : mp) cout << q.first << " " << q.second.first << " " << q.second.second << endl;
	
	ll ans = 0, ans_i;
	rep(i, 1, n){
		ll x = i; map<ll, ll> tmp;
		while(prime[x]){
			tmp[prime[x]]++;
			x /= prime[x];
		}
		if(x > 1) tmp[x]++;
		
		ll mul = 1;
		for(auto p : tmp){
			P q = mp[p.first];
			if(q.second >= p.second) continue;
			rep(i, 1, p.second-q.second) mul *= p.first;
		}
		//cout << i << " " << mul << endl;
		if(ans < mul) ans = mul, ans_i = i;
	}
	
	//cout << ans_i << endl;
	
	mp.clear();
	rep(i, 1, n){
		if(i == ans_i) continue;
		ll x = i; map<ll, ll> tmp;
		while(prime[x]){
			tmp[prime[x]]++;
			x /= prime[x];
		}
		if(x > 1) tmp[x]++;
		
		for(auto p : tmp){
			P q = mp[p.first];
			chmax(q.second, min(q.first, p.second));
			chmax(q.first, p.second);
			mp[p.first] = q;
		}
	}
	
	//for(auto q : mp) cout << q.first << " " << q.second.first << " " << q.second.second << endl;
	
	ans = 1;
	for(auto p : mp){
		rep(i, 1, p.second.first) ans *= p.first, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}
0