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 by1000000009 (109 + 9).

错误题数为n-m,可以n-m次在连续答对(k-1)道题时使下一道答错,共(n-m) * [(k-1) + 1] = (n-m)* k道题。

假设有x次连续答对k题,则有x * k + (n-m)* k + r = n,这里0 <= r < k,是余下的凑不成k道题目的题目数。得x = n / k - (n - m). 注意这里“/”是C++中向下取整的除法。

AC Code:

#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; const long long M = ; long long POW(long long y)
{
if(y == ) return ;
long long res = POW(y >> );
res = (res * res) % M;
if(y & ) res = (res << ) % M;
return res;
} int main()
{
long long n, m, k, s;
while(scanf("%I64d %I64d %I64d", &n, &m, &k) != EOF){
long long a = n / k;
long long b = n - m;
if(b >= a){
s = m;
}
else{
//a-b次连续答对k题,b次连续答对题数不足k
long long r = POW(a - b + ) - ;
if(r < ) r += M; //注意这里!
s = (k * r) % M;
s = (s + (m - (a - b) * k) % M) % M;
}
printf("%I64d\n", s);
}
return ;
}

Quiz(贪心,快速幂乘)的更多相关文章

  1. Codeforces1062C. Banh-mi(贪心+快速幂)

    题目链接:传送门 题目: C. Banh-mi time limit per test second memory limit per test megabytes input standard in ...

  2. 贪心,打表(或者快速幂), UVA - 11636

    题目链接: https://cn.vjudge.net/problem/34398/origin 题目比较简单,就是水题,基础贪心,大于所需的即可: AC代码: 打表: #include <cm ...

  3. Codeforces Round #209 (Div. 2)A贪心 B思路 C思路+快速幂

    A. Table time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  4. 小总结:快速幂+贪心————Bit Mask____UVA 10718 多多去理解去温习哦!

    传送门:https://vjudge.net/problem/UVA-10718 Preview: bitstream:a flow of data in binary form. in bit-wi ...

  5. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  6. 【BZOJ】2553: [BeiJing2011]禁忌 AC自动机+期望+矩阵快速幂

    [题意]给定n个禁忌字符串和字符集大小alphabet,保证所有字符在集合内.一个字符串的禁忌伤害定义为分割能匹配到最多的禁忌字符串数量(一个可以匹配多次),求由字符集构成的长度为Len的字符串的期望 ...

  7. Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check

    A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...

  8. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  9. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  10. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

    题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                  ...

随机推荐

  1. [Python爬虫] Selenium获取百度百科旅游景点的InfoBox消息盒

    前面我讲述过如何通过BeautifulSoup获取维基百科的消息盒,同样可以通过Spider获取网站内容,最近学习了Selenium+Phantomjs后,准备利用它们获取百度百科的旅游景点消息盒(I ...

  2. paip.自适应网页设计 跟 响应式 设计方法与工具补充(2)o54

    paip.自适应网页设计 跟 响应式 设计方法与工具补充(2)o54 #-----响应式 设计框架 Bootstrap比较热门. Foundation 号称是世界上最先进的响应式前端框架. #---绝 ...

  3. Java插件开发-取插件下的某个文件

    //找到插件所在处 Bundle bundle = Activator.getDefault().getBundle(); //根据插件转义成URL路径 URL url = FileLocator.t ...

  4. hdu 1087 动态规划之最长上升子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...

  5. hdu 1864 01背包 最大报销额

    http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  6. Moses在Ubuntu14.04平台的安装过程

    平台环境:在windows 7中建立VMware虚拟机,操作系统为Ubuntu_14.04_amd_64 1.安装GIZA++ 安装步骤如下: wget http://giza-pp.googleco ...

  7. Prototype in JavaScript

    声明 本文旨在入门,简单了解下何为prototype & __proto__ 原型对象 我们创建每个函数都有个prototype(原型)属性,该属性是一个指针,指向一个对象,而这对象的用途是包 ...

  8. cmdCreateViewTag

    start ).Y < grid.Curve.get_EndPoint().Y)                 {                     grid = gridTmp;    ...

  9. JavaScript中如何中断forEach循环

    先来看下forEach的实现 // Production steps of ECMA-262, Edition 5, 15.4.4.18// Reference: http://es5.github. ...

  10. Android 的EditText实现不可编辑

    android:editable is deprecated: Use an <EditText> to make it editable android:editable is depr ...