题解:P16341 [科大国创杯初中组 2026] 乘积
祺祺爱棋Thomas · · 题解
思路:先读入题目中所要的数据。然后从
注意:在循环中的乘积如果大于
代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, x;
int a[105];
signed main()
{
cin >> n >> x;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
int mul = 1;
for (int k = i; k <= j; k++)
{
if (mul > 10000)
{
mul = 1e9;
break;
}
mul *= a[k];
}
if (mul == x)
{
cout << i << " " << j;
return 0;
}
}
}
cout << -1;
return 0;
}