CodeForces - 337 C. Quiz【贪心】

来源:互联网 发布:jquery储存数据 编辑:程序博客网 时间:2024/05/18 04:44


C. Quiz
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.

Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109 + 9).

Input

The single line contains three space-separated integers nm and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).

Output

Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009(109 + 9).

Examples
input
5 3 2
output
3
input
5 4 2
output
6
Note

Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.

Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.

Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number.


AC代码:

#include<cstdio>typedef long long LL;const int MOD=1e9+9;LL Pow(LL base,LL y,LL MOD){LL ans=1;while(y) {if(y&1) ans=(ans*base)%MOD;y>>=1; base=(base*base)%MOD;} return ans; } int main(){LL N,M,K;while(~scanf("%lld%lld%lld",&N,&M,&K)){LL S=N%(K)+N/K*(K-1);LL ans=0;if(S>=M) {ans=M;} else {    LL tem=M-S;     ans=(Pow(2,tem+1,MOD)+MOD-2)%MOD*K%MOD;     ans=(ans+M-(M-S)*K);}printf("%lld\n",(ans%MOD+MOD)%MOD);}return 0;}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 奋发人生 爷爷奶奶的奋斗力史 爷爷趴在玉婷的身上 朋友的妻子字幕中文翻译 露脸怀孕嫂嫂在线播放 中文字幕侵犯妻子在线疯人院 硬上嫂嫂在线 在线播放 怀孕 中文字幕女老师在线播放 丈夫经常晚归妻子不满离婚 农村孕妇对白 年轻母亲9完整高清免费观看 国产孕妇碰碰碰 厨房侵犯中文字幕 我邻居的妻子中文字幕在线 怀孕全部过程视频播放 水电工在厨房和妻子的视频 妻子出轨水电工在线播放 老公把婆婆干怀孕 在丈夫面前被侵 中文字幕全集 部长的妻子味道中文字幕 中文字幕被水电工掠夺的妻子 妻子在厨房跟水电工 互动 妻子与水电工在线 丈夫出差妻子与水电工 樱萌子被水电工侵犯中文字幕 在丈夫的面前侵犯入侵中文字幕 好妻子在线中文字幕 前田香织侵犯中文字幕 佐佐木明希上司中文字幕迅雷 医生d淫孕妇 公公一晚上要8次 公公现在就想要白关婷中文字幕 丈夫上司侵犯系列在线 义父犯美媳嫁樱花叶菜在线播放 儿子的妻子在线中文字幕云播 老公去世公公每天晚上抱着我睡 被水电工掠夺的妻子在线播放b 佐佐木明希大嫂中文字幕全集 善良的小妻子字幕 公公在我洗碗时在厨房要了我 大嫂被肉翻了天佐佐木明希1