### divyamsingal01's blog

By divyamsingal01, 2 months ago, So I did not find a tutorial for Maths section of CSES on codeforces, so thought of writing one.

I have put all my codes on https://github.com/div5252/CSES-Problem-Set.

This is now a complete tutorial, covering all the 21 questions of Mathematics Section of CSES.

1. Exponentiation

Tutorial
Code

2. Exponentiation II

Tutorial
Code

3. Counting Divisors

Tutorial
Code

4. Common Divisors

Tutorial
Code

5. Sum of divisors

Tutorial
Code

6. Binomial Coefficients

Tutorial
Code

7. Creating Strings

Tutorial
Code

8. Distributing Apples

Tutorial
Code

9. Christmas Party

Tutorial
Code

10. Fibonacci Numbers

Tutorial
Code

11. Throwing Dice

Tutorial
Code

12. Graph Paths I

Tutorial
Code

13. Graph Paths II

Tutorial
Code

14. Dice Probability

Tutorial
Code

15. Moving Robots

Tutorial
Code

16. Candy Lottery

Tutorial
Code

17. Inversion Probability

Tutorial
Code

18. Stick Game

Tutorial
Code

19. Nim Game I

Tutorial
Code

20. Nim Game II

Tutorial
Code

21. Stair Game

Tutorial
Code Comments (17)
 » Thanks man...
 » Thanks a lot!
 » UPD: The tutorial is now complete. I have put the explanations and codes for all 21 problems.If you find any typo or any improvement in the explanation, please comment below.I haven't put the complete code(template portion) in the tutorial above, so as to prevent people for directly copying. Still if you wish to see the complete code, I have to the link to my github which contains AC solutions.
 » I still do not get sum of divisors :(
•  » » 2 months ago, # ^ | ← Rev. 2 →   link this might help, see the last answer
•  » » Yeah sorry, I have updated the explanation. I hope it is clear now.
•  » » » Thanks
 » THanks bro!
 » 2 months ago, # | ← Rev. 3 →   divyamsingal01 can you share the links to the editorials of other sections if you have found them?
•  » » 2 months ago, # ^ | ← Rev. 2 →
 » 2 months ago, # | ← Rev. 4 →   can you please verify if i understood moving robots correctly — for each robot we first get what is the probability for it to be on some i, j cell after k iterations.then for each cell what is the probability that it was empty after k iterns? — probability that robot 1 isnt there * probability that robot 2 isnt there and so on.... so we multiply the 1 — dp[i1][j1]now expectation — sum(P(xi)*xi) we calculated P(xi) and xi is 1?
 » 2 months ago, # | ← Rev. 2 →   For 21, here's a fairly straightforward proof:This game is essentially equivalent to Nim with a restricted number of additions permitted, with the piles being on the even indices, and the permitted additions being precisely the ones which can be done due to the shift from the pile on the immediate right (if it exists), with the only other possible move being removal of one element from an even pile at most a finite number of times, and thus this game is equivalent to vanilla Nim (proof here: https://cp-algorithms.com/game_theory/sprague-grundy-nim.html#toc-tgt-5), from where it is obvious.
 » divyamsingal01 can you pleaes elaborate on second problem Exponentiation II. I don't know much about Fermat's theorem.
•  » » fermat's theorm says that if a,m are coprime and m is prime. then pow(a,m-1)%m = 1.
 » Thankyou so much for the contribution
 » dardev cdes graph and yours math are the best!!
 » Would you care to explain the question Exponentiation II again? I tried to solve it using simple Binary exponentiation but got WA. I see you're using Fermat there what is the reason behind it. can we not solve it using simple Binary Exponentiation?
{"ft_lang_label":"__label__en","ft_lang_prob":0.5497965,"math_prob":0.78172266,"size":21808,"snap":"2020-45-2020-50","text_gpt3_token_len":7645,"char_repetition_ratio":0.14607412,"word_repetition_ratio":0.24707793,"special_character_ratio":0.40819883,"punctuation_ratio":0.17636263,"nsfw_num_words":1,"has_unicode_error":false,"math_prob_llama3":0.99492514,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,6,null,4,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-30T10:22:23Z\",\"WARC-Record-ID\":\"<urn:uuid:4484fa96-4207-4d1c-a6ab-f6fee0bccfc5>\",\"Content-Length\":\"168872\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:012cdb8e-ee5d-410f-a197-85f1454b33fc>\",\"WARC-Concurrent-To\":\"<urn:uuid:052ed019-f3d8-4e0b-8e2b-32e3656a2bf9>\",\"WARC-IP-Address\":\"81.27.240.126\",\"WARC-Target-URI\":\"http://codeforces.com/blog/entry/82103\",\"WARC-Payload-Digest\":\"sha1:MYRRTI7IZ35SKJ4ZUSUXKRPPBCK5YH2E\",\"WARC-Block-Digest\":\"sha1:AA5MQCRRSN3Q4HJB6HIOORIZ26T2EGW4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107910204.90_warc_CC-MAIN-20201030093118-20201030123118-00214.warc.gz\"}"}