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 | Benq | 3650 |

2 | Radewoosh | 3648 |

3 | tourist | 3579 |

4 | ecnerwala | 3551 |

5 | Um_nik | 3494 |

6 | Petr | 3452 |

7 | ksun48 | 3432 |

8 | jiangly | 3349 |

9 | maroonrk | 3338 |

10 | Miracle03 | 3314 |

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

1 | 1-gon | 211 |

2 | awoo | 188 |

3 | rng_58 | 185 |

3 | Errichto | 185 |

5 | SecondThread | 182 |

6 | Ashishgup | 175 |

6 | Um_nik | 175 |

8 | maroonrk | 174 |

9 | antontrygubO_o | 170 |

10 | -is-this-fft- | 169 |

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: May/18/2021 07:38:21 (g2).

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.