You are not logged in. Please login at www.codechef.com to post your questions!

×

Help needed in CSEQ - April15 Long Challenge

I was trying to understand this solution. But I'm not able to get what does the following code do?

long long factorial(int n)
{
    long long res = 1; 
    while (n > 0)
    {
        for (int i = 2, m = n % MOD; i <= m; i++)
            res = (res * i) % MOD;
        if ((n /= MOD) % 2 > 0) 
            res = MOD - res;
    }
    return res;
}

Can someone please help?

asked 21 Apr '15, 15:45

ksharma377's gravatar image

4★ksharma377
111
accept rate: 0%

edited 21 Apr '15, 20:20

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×900
×344
×35

question asked: 21 Apr '15, 15:45

question was seen: 1,186 times

last updated: 21 Apr '15, 20:20