https://codeforces.com/problemset/problem/1016/A

Why should I modulo the variable ? I couldn't understand the mathematical things they have used in the tutorial.

# | User | Rating |
---|---|---|

1 | tourist | 3748 |

2 | Benq | 3540 |

3 | Petr | 3470 |

4 | Radewoosh | 3355 |

5 | ecnerwala | 3347 |

6 | maroonrk | 3345 |

7 | jiangly | 3324 |

8 | scott_wu | 3313 |

9 | ainta | 3298 |

10 | boboniu | 3289 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 200 |

2 | Errichto | 196 |

3 | rng_58 | 194 |

4 | SecondThread | 186 |

4 | awoo | 186 |

6 | Um_nik | 182 |

7 | vovuh | 179 |

8 | Ashishgup | 176 |

9 | -is-this-fft- | 173 |

9 | maroonrk | 173 |

https://codeforces.com/problemset/problem/1016/A

Why should I modulo the variable ? I couldn't understand the mathematical things they have used in the tutorial.

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/02/2021 21:06:27 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Hey!

Here you don't turn the page unless you have more than 'm' names to write. Suppose, on some day, you have more than 'm' names that you have to write, i.e., a[i] > m, then you have to turn the page a[i]/m times.

The above, is assuming you start from fresh page every time.

But since you continue writing on the same page, you might have a partially filled page at the end of the day. So you need to continue from that page itself.

modulo(%) gives the remainder on division. So, for any 'a' and 'b', you can write a = floor((a/b)) * b + a%b.(dividend = divisor * quotient + remainder).

Here a/b gives the number of turns of pages, while a%b gives the measure of 'how much of the newest page is filled'.

Taking an example n= 3, m= 5 a = [3, 7, 9]

On the first day, you have to write 3 names. Since page length is 5 names long, you don't have to turn pages.

On second day, you will have to write 7 names. Since you have to start where you left off, at the end of second day, you have written 10 names(3 in first day, 7 in secod). You write first 2 names in the first page, filling it, then write next 5 names in the second. So you have turned 2 pages at the end of second day. Since 2 pages exactly hold 10 names written so far, you will start from fresh page. Note that you will turn the page immediately after it is filled.

On the third day, you have to write 9 names. You write 5 names, turn the page, then write 4 names.

Printing the result of a/b and update the number of names written in the newest page in each iteration.

The C++ code is here.