The code gives me correct answer on my computer but it shows wrong when I submit

The link to the question is here: CodeChef: Practical coding for everyone

I have run all the test cases on my computer(Using XCode on mac) and they give the expected out. But the answer still comes out to be wrong on CodeChef.

The question clearly states to print each answer in a new line. you need to replace cout<<sum; with cout<<sum<<"\n";

Thanks! That works.

@everule1 The same happens to me in this problem as well. CodeChef: Practical coding for everyone

I am already printing numbers on a new line…

Okay tell me what is 100! ? do you think it’s lesser than 4\times10^{18} ? Will it fit in any standard datatype?

I don’t think so… that is why I used long long int. If something is even bigger than that, how do I handle the numbers?

There are 2 ways. Use a digit vector, or use python.

I have not yet learned Python. I recently finished C++ and I would like to practice more with it before moving on to other languages. Can you please tell me about a reliable and good resource(website) where I can learn about “digit vector”?

I am familiar with the concept of vectors but digit vector is new to me.

read the article about big integer in c++ on geekforgeeks. then implement it yourself.

I don’t know where to learn it but it’s not complex at all. we just code how we do multiplication.

int digits1[160]={0};//100! has 157 digits
     int digits2[160]={0};
     for(int i=2;i<=n;i++){
         for(int j=0;j<160;j++){
             digits2[j]+=digits1[j]*i;//we multiply the digit
             digits1[j]=0;  //we set it to 0, for the next multiplication
             digits2[j+1]+=digits2[j]/10; //add the carryover to the next digit
             digits2[j]%=10; //remove the carryover from here

Thank you @everule1! That helps :slight_smile: