F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Good Numbers

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 285    Accepted Submission(s): 84


Problem Description
Let¡¯s consider a number N is good if and only if the occurrence of each digit is multiple of 3 in the octonal representation of N.
You are good at math, so we want to ask you to calculate how many good numbers with K digits in octonal representation, which are multiple of P. This number may be huge, so you are only to print it modulo 10^9 + 9.
Note that good numbers should be positive and should not have any leading zeroes.
For example, suppose K = 3 and P = 2, good numbers are 222(8), 444(8) and 666(8). 111(8) is not good because it is not the multiple of 2. 102(8) is not good because 1 occurs once, not multiple of 3.
 

Input
There are multiple (at most 100) test cases. Please process until EOF (end of file).
Each test case contains 2 integers K (1 <= K <= 10^18, K is divisible by 3), P (<8).
At most 15 test cases are big. (K > 1000).
 

Output
For each test case, print a single integer denoting the answer in one line.
 

Sample Input
3 1 3 2
 

Sample Output
7 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 22:11:57, Gzip enabled