Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

ANT - Kiến

Ants

To celebrate the New Year, the ants gather along a circle and play a game together. The queen announces a number, call it M and start by counting 1. In clockwise order, the ants continue to count the next numbers in turn. Who counts M has to go out of the circle. The next ant (in clockwise order) restarts counting from 1.

The game ends when there is only one ant left. This ant will get a new-year gift from the queen.

Given M and the number of ants in the circle, determine the lucky ant that will receive the new-year gift. The ants are numbered in clockwise order, starting from the queen of index 1.

Input

  • Line 1: a positive integer N that is the number of ants in the circle.
  • Line 2: a postive integer M.

Output

Only one line containing the lucky ant's index.

Constraints

  • 1 ≤ N ≤ 1012.3 ≤ M ≤ 106.
  • M ≤ N.

Example

Input
7 
3

Output
4

Output details
The ants 3 6 2 7 5 1 in turn have to go out of the circle.
Ant 4 is the lucky one!


Được gửi lên bởi:VOJ Team
Ngày:2008-07-21
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST WHITESPACE
Nguồn bài:VNOI Marathon '08 - Round 11/DivB
Problem Setter: Ngô Minh Đức

hide comments
2014-08-13 16:34:43 Nguyễn Tùng Dương
Q
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.