PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000275. Phân phối kẹo (Candy Distribution)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân phối kẹo (Candy Distribution)

Candy Distribution

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are KK children and each bag contains exactly CC candies. Buy a positive integer number YY of bags so that every child receives the same positive number XX of candies and exactly one candy remains. At most 10910^9 bags can be purchased.

Equivalently, find positive integers X,YX,Y satisfying CY=KX+1CY=KX+1 and 1≤Y≤1091\le Y\le10^9. Output IMPOSSIBLE if no such pair exists; otherwise output any valid number YY of bags.

Input

One line contains two integers K,CK,C: the number of children and candies per bag.

Output

Print a valid integer YY, or IMPOSSIBLE if none exists.

Subtasks

  • Subtask 1 (20 points): 1≤K,C≤1001\le K,C\le 100; 1≤Y≤1091\le Y\le10^9 if a solution exists.
  • Subtask 2 (30 points): 1≤K,C≤1000001\le K,C\le 100000; 1≤Y≤1091\le Y\le10^9 if a solution exists.
  • Subtask 3 (50 points): 1≤K,C≤9999999991\le K,C\le 999999999; 1≤Y≤1091\le Y\le10^9 if a solution exists.

Examples

Example 1

Input

10 5

Output

IMPOSSIBLE

Explanation

gcd⁡(10,5)=5>1\gcd(10,5)=5>1, so CY−KX=1CY-KX=1 has no integer solution.

Example 2

Input

10 7

Output

3

Explanation

For K=10,C=7,Y=3K=10, C=7, Y=3, the total candies are 7⋅3=21=10⋅2+17\cdot 3=21=10\cdot 2+1. Each child receives 22 candies with one left over.

Example 3

Input

1337 23

Output

872

Explanation

For K=1337,C=23,Y=872K=1337, C=23, Y=872, the total candies are 23⋅872=20056=1337⋅15+123\cdot 872=20056=1337\cdot 15+1. Each child receives 1515 candies with one left over.

Example 4

Input

123454321 42

Output

14696943

Explanation

For K=123454321,C=42,Y=14696943K=123454321, C=42, Y=14696943, the total candies are 42⋅14696943=617271606=123454321⋅5+142\cdot 14696943=617271606=123454321\cdot 5+1. Each child receives 55 candies with one left over.