Sausage Sharing

Time limit1sMemory limit128 MB

Summary
Given N identical sausages split among M critics who must each receive an equal total amount, find the minimum number of cuts required.
Level

Medium5 of 10

Topics
Number theory, Math, Greedy
Solved
No attempts yet

Problem

Sunyoung has prepared N identical sausages for M food critics. She wants to cut the sausages so that every critic receives exactly the same total amount of sausage.

Find the minimum number of cuts required.

Input

The first line contains two integers N and M, the number of sausages and the number of critics.

  • 1 <= N, M <= 100

Output

Print the minimum number of cuts needed so that all critics can receive the same amount.

Examples3

  1. Example 1

    Input
    2 6
    
    Expected output
    4
    
  2. Example 2

    Input
    3 4
    
    Expected output
    3
    
  3. Example 3

    Input
    6 2
    
    Expected output
    0