ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1537. Ents

please help, crash... stack overflow, here's code:
Posted by radio 21 May 2008 05:33
#include <iostream.h>
#define MAX 10000000
using namespace std;
int main()
{
    __int64 k,p,i;
    __int64 A[MAX];
    cin>>k>>p;

    A[0] = 0;
    A[1] = 1 % p;
    for(i = 2; i <= k; i++){
        if(i % 2 == 0)
            A[i] = (A[i-1] + A[i / 2]) % p;
        else
            A[i] = A[i-1] % p;
    }
    cout<<A[k-1];
    return 0;
}

Edited by author 21.05.2008 05:37
Re: please help, crash... stack overflow, here's code:
Posted by Alias aka Alexander Prudaev 21 May 2008 19:11
local variables are located in stack, so
if you want to avoid stack overflow(crash)
you can't declare big arrays inside functions

int main()
{
__int64 k,p,i;
__int64 A[MAX];

=>

__int64 A[MAX];

int main()
{
__int64 k,p,i;