Winner
题号:NC205194
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

This is the hard version of the problem. The difference is the constraint of n and m.
N gamblers (numbered from 1 to n) circle the round table clockwise. There is a large electronic screen and a large amount of money on the round table. They want to play a game. Before the game starts, the electronic screen will randomly display a positive integer M. they will start counting clockwise from  1, and the person who reports the number m will exit, and then the first person behind him will continue counting from 1, Repeat this until only one left. Then he will win all the money. But this person is a hacker. He has set the number to be displayed on the electronic screen in advance to ensure that he is the winner of the game. Your task is to find the hacker's number.

输入描述:

The first line  contains two integers n,m (1≤n,m≤2000000).

输出描述:

Print the hacker's number.
示例1

输入

复制
11 3

输出

复制
7