Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Confusion regarding modulo operaor

$
0
0

Referring to this solution http://www.codechef.com/viewsolution/3331816 (got AC) for the question http://www.codechef.com/problems/CLMBSTRS, i came across teh confusion regarding modulo operator. I initially framed the array fib[] this way

for(i=2;i<=MAX;i++) { fib[i]=(fib[i-1]%mod+fib[i-2]%mod); } and this gave WA. I, just in case,changed the above to

for(i=2;i<=MAX;i++) { fib[i]=(fib[i-1]+fib[i-2])%mod; }

and this gave AC. As far as i know (a+b)%mod = a%mod + b%mod, then why such??


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>