Alice and her sheep Ⅰ
题号:NC207663
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Alice lives on a farm, and one day she bought N sheep (she had not previously). Due to the reproduction of sheep, the number of sheep will double every D days. Since Alice does not want the number of sheep to be too large, she will sell half of the sheep she owns every R days (If it doubles and sells on the same day, then the sheep doubles first). But Alice is still worried that the number of sheep will be very large, so she wants you to tell her what the number of sheep will be after M days? In order to avoid an overly large answer, please output the result mod 1e9 + 7.

输入描述:

One line consists of four integers,respectively: N, D, R, M.
Data guarantee:.

输出描述:

An integer representing the number of sheep after m days (mod 1e9 + 7).

示例1

输入

复制
1 1000 1001 999

输出

复制
1

说明

Not doubled, nor sold
示例2

输入

复制
1 1000 1001 1000

输出

复制
2

说明

Only doubled, not sold