405865: GYM102136 G A Bishop's Journey

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. A Bishop's Journeytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Once upon a time there was an unusual bishop who lived on an unusual chess board. The board was unusual because it was of an arbitrary size N × M. The bishop was unusual because it was placed in the corner field of the board. It stood there for a long time and got bored. And so it decided to go on a journey wherever its eyes lead him. As is well known, the eyes of bishops lead them diagonally. Having reached the edge of the board, the bishop turned through 90 degrees and continued to move. And so on. The bishop had stopped only when again got into some (first available) corner.

How many unique fields did it visit during his journey around the N × M board?

Input

The first and only line contains integers N and M — the chess board sizes.

1 < N ≤ 1018
1 < M ≤ 1018
Output

The single line contains the only number —required number of visited fields by prime modulo 1018 + 9.

ExampleInput
15 22
Output
42

加入题单

算法标签: