0

I was working on a codeblocks project, but when I tried to bild/run the code, I got the error code c00000fd. I never heard of it, and I could't find it anywhere on the Internet. I would like to know at least what does the code mean but if you could help me fix my project i would be gratefull. Here is the code:

#include <fstream>

using namespace std;
ifstream fin("forta.in");
ofstream fout("forta.out");
int main()
{
    int p,n,maxx=0;
    long long x,minn=2000000000;
    fin>>p>>n;
    if(p==1)
    {
        for(int i=0; i<n; i++)
        {
            fin>>x;
            long long divt=1,p,cx=x,m=0;
            long long frp[2000000000],prim[2000000000];
            frp[0]=0;
            frp[1]=0;
            for(int i=2; i<=x; i++)
                frp[i]=1;
            for(int i=2; i<=x; i++)
            {
                if(frp[i]==1)
                {
                    prim[m++] =i; ///stochez nr prime
                    for(int j=i+i; j<=x; j=j+i)
                        frp[j]=0;
                }
            }
            for(int i=0; i<m ; i++) ///  sirul de nr prime
            {
                p=0;

                while(x%prim[i]==0)
                {
                    p++;
                    x=x/prim[i];
                }
                divt=divt*(p+1);

            }
            if(divt>maxx)
            {
                maxx=divt;
                minn=cx;
            }
            else if(divt==maxx)
            {
                if(cx<minn)
                    minn=cx;
            }
        }
        fout<<minn;
    }
    if(p==2)
    {
        int fr[20000]= {0}, maxx=0;
        for(int i=0; i<n; i++)
        {
            fin>>x;
            long long divt=1,p,cx=x,m=0;
            long long frp[x+1], prim[x+1];
            frp[0]=0;
            frp[1]=0;
            for(int i=2; i<=x; i++)
                frp[i]=1;
            for(int i=2; i<=x; i++)
            {
                if(frp[i]==1)
                {
                    prim[++m] =i; ///stochez nr prime
                    for(int j=i+i; j<=x; j=j+i)
                        frp[j]=0;
                }
            }
            for(int i=0; i<m ; i++) ///  sirul de nr prime
            {
                p=0;

                while(x%prim[i]==0)
                {
                    p++;
                    x=x/prim[i];
                }
                divt=divt*(p+1);

            }
            fr[divt]++; /// frecventa pe nr de div
            if(maxx<fr[divt])
                maxx=fr[divt];
        }
        fout<<maxx;
    }
    return 0;
}

And here is the complete error report: Problem signature:

Problem Event Name: APPCRASH
  Application Name: OJI_2020_A6-A_forta.exe
  Application Version:  0.0.0.0
  Application Timestamp:    604a50ce
  Fault Module Name:    OJI_2020_A6-A_forta.exe
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   604a50ce
  Exception Code:   c00000fd
  Exception Offset: 0000000000003146
TudorTeo
  • 113
  • 11
  • If you do a quick search for e.g. `windows exception c00000fd` you will find out that it's a stack exhaustion error. And if you read [some decent books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to learn instead of using "competition" sites you would know that local variables (including arrays) are stored on the stack. And that the size of stacks are limited. On Windows it's by default a single MiB. Now how large are your arrays `frp` and `prim`? – Some programmer dude Mar 12 '21 at 07:35
  • 2
    Probably because of `long long frp[2000000000],prim[2000000000];` if `sizeof(long long) == 8` you request roughly 30GB of stack memory. – churill Mar 12 '21 at 07:35
  • churill, I'l try to make them smaller – TudorTeo Mar 12 '21 at 07:37
  • 1
    @TudorTeo Keep in mind that the stack is _really_ small. 1MB on Windows, you should use `std::vector` to allocate on the heap instead. – churill Mar 12 '21 at 07:38
  • @TudorTeo a side note: vector certainly seems like the best option for this case, but when you want to use an array, consider using `std::array` as opposed to C-arrays (the kind you are using right now). It helps keep you safe from possible mistakes you could make with C-arrays, have iterators and can thus be used in useful standard library functions in ``. – mediocrevegetable1 Mar 12 '21 at 07:49
  • @TudorTeo: If you look at Some Programmer Dude's profile, you'll notice that he has multiple answers with hundreds of upvotes. Het's got a point. Your code is _seriously_ flawed, with outright errors like `long long frp[x+1]` (non-const array bound). – MSalters Mar 12 '21 at 11:05
  • Maybe ask user [c00000fd](https://stackoverflow.com/users/843732/c00000fd) :P – DimP May 31 '22 at 15:55

0 Answers0