传送门:洛谷 Chaya Calendar | Codeforces B. Chaya Calendar
更佳的阅读体验:CF1932B 题解
简要题意:有 $n$ 个征兆,每个征兆每 $a_i$ 年就会出现一次。征兆必须按 $1$ 到 $n$ 的顺序出现,求出现第 $n$ 个征兆在哪一年。
根据题意,可以知道第 $i$ 个征兆一定在第 $i - 1$ 征兆之后发生,因此我们只需要记录第 $i - 1$ 个征兆在哪一年发生即可。
对于第 $i$ 个征兆,每隔 $a_i$ 年就会出现一次,所以直接求出 $a_i$ 的大于第 $i - 1$ 个征兆发生年份的最小倍数即可。
#include <iostream>
using namespace std;
using ll = long long;
int t, n, x;
ll ans;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (cin >> t; t; --t) {
ans = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> x, ans = x * ((ans + x) / x);
cout << ans << '\n';
} return 0;
}