我从uva上的此问题收到第三输入的运行时错误。我不知道我的代码在哪里中断。
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=349
#include <bits/stdc++.h>
using namespace std;
int main() {
long int step,mod,i=0,temp;
cin >> step >> mod;
int count[mod+1] = {0};
count[0] = 1;
vector<int> seed;
seed.push_back(0);
while(true)
{
seed[i+1] = (seed[i]%mod + step%mod)%mod;
temp = seed[i+1];
if(temp == 0)
{
break;
}
count[temp] += 1;
++i;
}
bool flag = true;
for(int i=0; i<mod; i++)
{
if(count[i] <= 0)
{
flag = 0;
break;
}
}
if(flag)
cout << "Numbers have been generated\n";
else
cout << "Wrong choice\n";
return 0;
}
答案应该是“不错的选择”,即我程序上的输出应为Numbers have been generated
,但显示运行时错误。