CF 337C (nesting Quiz-pow2)

Source: Internet
Author: User

C. Quiz
Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard 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 has CES 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 bytes + limit 9 ).

Input
The single line contains three space-separated integers n, m and k (2 ≤ 1_k ≤ 1_n ≤ 1_109; 0 ≤ 1_m ≤ 1_n ).

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

Sample test (s)
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 wocould double for each two consecutive correct answers. if Manao had answered the first, third and th questions, he wowould 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 cocould obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though2000000020 mod 1000000009 is a smaller number.

 

 

 

 

This is a big question...

But I forgot to change the inner loop to pow2 when writing the power quickly ,.. Incorrect policies ,,,

Pia Fei (weak test)

#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000009)long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+abs(a-b)/F*F+F)%F;}typedef long long ll;ll n,m,k;ll pow2(ll a,int b){if (b==0) return 1;if (b==1) return a%F;ll p=pow2(a,b/2);p=p*p%F;if (b%2) p=p*a%F;return p;}int main(){//freopen("Quiz.in","r",stdin);//freopen(".out","w",stdout);//For(i,100) cout<<pow2(2,i)<<' ';cin>>n>>m>>k;ll m1=m;m=n-m;int maxk=n/k;if (m>=maxk) {cout<<m1%F<<endl;return 0;}else m=maxk-m;ll am=sub((4*pow2(2,m-1))%F,2);ll ans=add(am*k%F,m1-k*m);cout<<ans%F<<endl;return 0;}

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.