注意到有t组数据哦
时间: 2024-02-11 15:08:35 浏览: 14
非常感谢您的提醒,以下是修改后的带有多组数据的 C++ 代码实现:
```cpp
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int MAXK = 1e9 + 5;
int t, n, k;
ll a[MAXN], p2[MAXN], p5[MAXN];
unordered_map<ll, ll> cnt;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
while (a[i] % 2 == 0) {
p2[i]++;
a[i] /= 2;
}
while (a[i] % 5 == 0) {
p5[i]++;
a[i] /= 5;
}
}
ll ans = 0;
cnt[0]++;
for (int i = 1; i <= n; i++) {
ll key = (p2[i] - p2[i - 1]) * MAXK + p5[i] - p5[i - 1] - k;
ans += cnt[key];
cnt[key]++;
}
cout << ans << endl;
// clear variables for next test case
for (int i = 1; i <= n; i++) {
p2[i] = p5[i] = 0;
}
cnt.clear();
}
return 0;
}
```
在这个版本的代码中,我们使用了一个外层循环来处理多组数据。具体来说,我们首先读入测试数据的数量 `t`,然后循环 `t` 次,每次读入一个测试数据并处理。处理完当前测试数据后,我们需要清空一些变量,以便处理下一个测试数据。
希望这个版本的代码能够满足您的需求。如果还有任何问题,请随时告诉我。