大输入C ++上的运行时错误

时间:2015-11-14 09:56:05

标签: c++

当n< =(10 ^ 4)时,我的程序似乎正常工作。 但对于像10 ^ 5这样的输入,ideone会给出运行时错误plz帮助 ideone链接Code

enter code here

#include <iostream>
using namespace std;

int main()
{
    long long int t,i=0,n,j,sum;
    cin>>t;
    while(i<t)
    {
        cin>>n;
        cout<<n+1<<endl;
        sum=(n*(n+1))/2;
        cout<<sum<<endl;
        for(j=0;j<=n;j++)
        cout<<j<<" ";
        i++;
        cout<<endl;
    }
    return 0;
}

1 个答案:

答案 0 :(得分:2)

Ideone 中的输出大小必须为<=64KB。考虑到sizeof(int) = 4,它将最多运行n=16000。这将为您提供输出限制的粗略估计。

相关问题