2015
09-17

# Dice

Given a normal dice (with 1, 2, 3, 4, 5, 6 on each face), we define:
F(N) to be the expected number of tosses until we have a number facing up for N consecutive times.
H(N) to be the expected number of tosses until we have the number ’1′ facing up for N consecutive times.
G(M) to be the expected number of tosses until we have the number ’1′ facing up for M times.
Given N, you are supposed to calculate the minimal M1 that G (M1) >= F (N) and the minimal M2 that G(M2)>=H(N)

The input contains multiple cases.
Each case has a positive integer N in a separated line. (1<=N<=1000000000)
The input is terminated by a line containing a single 0.

The input contains multiple cases.
Each case has a positive integer N in a separated line. (1<=N<=1000000000)
The input is terminated by a line containing a single 0.

1
2
0

1 1
2 7

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define mod 2011
typedef long long ll;

inline ll Pow(ll a,ll n)
{
ll ans=1,t=a;
while(n)
{
if(n%2) ans=ans*t%mod;
n/=2;
t=t*t%mod;
}
return ans;
}
ll n;
int main()
{
while(~scanf("%I64d",&n))
{
ll m1,m2;
ll ny=Pow(5,mod-2);
m2=(Pow(6,n)-1+mod)%mod*ny%mod;

ny=Pow(30,mod-2);
m1=(Pow(6,n)+24)%mod*ny%mod;
printf("%I64d %I64d\n",m1%mod,m2%mod);
}
//system("pause");
return 0;
}