RGPC '18 P1 - Giant Cookie

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Elton has a giant cookie that he'd like to share with the rest of the CS club. The cookie is preemptively broken up into N equal pieces, but he soon realizes that N people might not be present at the club's next meeting! He will only share his cookie if he is sure that there will be no pieces remaining after it is equally divided amongst the club members.

Given the number of pieces there are, as well as the number of people that will be present at the club's next meeting, determine if Elton will share his cookie, and if so, how many pieces each person will get. Otherwise, determine how many additional people would need to be present in order for him to share it.

Input Specification

The first and only line of input will contain two space-separated integers N and M (1 \le M \le N \le 5\,000), representing the number of pieces the cookie has already been broken up into, as well as the number of people that will be present at the next club meeting, respectively.

Output Specification

If Elton will share his cookie, output yes X, where X is the number of pieces that each person will get. Otherwise, output no Y, where Y is the smallest number of additional people needed to attend the meeting in order for the cookie to be shared.

Sample Input 1

8 4

Sample Output 1

yes 2

Sample Input 2

13 7

Sample Output 2

no 6


  • 0
    KenzoEngineer  commented on April 17, 2018, 8:59 p.m.

    It looks like I'm doing it correctly can someone point out my error?

  • 0
    Korossgame  commented on April 14, 2018, 4:17 p.m.

    [Help] What's wrong with this task?I made it, I have all correct answers,but system just say they are not correct.

    Code[py3.6.5]: https://gist.github.com/KorossGame/dd8c197f477f73ec36e5e5e5acc42f1f

    • 0
      wleung_bvg  commented on April 14, 2018, 7:05 p.m.

      The solution for the case when the answer is no is a little more complicated. Look at the comments below for more information..

  • 3
    aeternalis1  commented on Feb. 25, 2018, 10:10 p.m.

    Note that the question asks for the minimum number of extra people so that the cookie pieces can be split evenly, not the number of leftover pieces. For example, the test case 21 4 should output 3, rather than 1.

  • 0
    SuperCyther  commented on Feb. 25, 2018, 9:48 p.m.

    What is wrong with my code?