SIGXFSZ runtime error

In Bytelandian gold coin problem , my initial solution was

It was showing Runtime error SIGXFSZ , after that i changed my solution to and it worked.

I need to know what is the difference between cin/cout and scanf/printf .

Well the basic difference is that

scanf() returns -1 while it stop getting inputs (get EOF)


cin returns 0

you tried to read after end of input file OR
your code having scanf was never terminated !! and Hence It gave large outputs
and hence you got runtime error SIGXFSZ
While cin returned 0 and your program got terminated…
This is I might think the problem is…
Changing while condition to


would definitely give AC…


Reading inputs after EOF gets this error sometimes

For this problem, you have to take input until EOF. But you are taking input using test case.

Try this code:

    #include <bits/stdc++.h>
    using namespace std;
unordered_map <int,long long int> a;
 long long int coins(int n){
    if(n<12){return n;}
   if(a[n]!=0){return a[n];}
   a[n] =  coins(n/2) + coins(n/3) + coins(n/4);
   return a[n];
int main()
    int n;
    return 0;

I think he was expecting scanf to return 0 when it doesn’t get input and thus his code failed… while cin do returned 0 and hence it worked…

Yes U said write…:slight_smile: