結果

問題 No.2610 Decreasing LCMs
ユーザー AerenAeren
提出日時 2024-01-19 22:29:33
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,074 bytes
コンパイル時間 3,201 ms
コンパイル使用メモリ 256,640 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-19 22:29:38
合計ジャッジ時間 4,349 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<int> a(n);
	a[n - 1] = 1 << __lg(100'000'000);
	a[n - 2] = a[n - 1] / 2;
	vector<array<int, 2>> dif(n - 1);
	dif[n - 2] = {1, 2};
	for(auto i = n - 3; i >= 0; -- i){
		int num = dif[i + 1][1];
		while(gcd(a[i + 1], num) != 1 || 1LL * num * a[i + 1] <= lcm<long long>(a[i + 1], a[i + 2])){
			++ num;
		}
		int den = num + 1;
		while(a[i + 1] % den){
			++ den;
		}
		dif[i] = {num, den};
		a[i] = a[i + 1] / den * num;
	}
	ranges::copy(a, ostream_iterator<int>(cout, " "));
	cout << endl;
	assert(ranges::max(a) <= 100'000'000);
	for(auto i = 0; i < n - 1; ++ i){
		assert(a[i] < a[i + 1]);
	}
	for(auto i = 1; i < n - 1; ++ i){
		assert(lcm<long long>(a[i - 1], a[i]) > lcm<long long>(a[i], a[i + 1]));
	}
	return 0;
}

/*
19 17 13 11 7  5  3
 1  2  4 8 16 32 64
a<b<c
 g h
ab/g > bc/h
a/g > c/h

13 11 9 7 5
1 2 4 8 16
*/
0