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

Periodic Binary String

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 86    Accepted Submission(s): 7


Problem Description
Teacher Mai has an infinite periodic binary string S with index counting from 0. That means S=TTTT..., where T is the period of string S. For example, T="101", then S="101101101101..."

S[l,r] is the sub-string of S. We define f[l,r] is the value when regarding S[l,r] as a binary number.

Please count the number of binary strings T with length k, where T is the period of string S, satisfying the condition: f[l,r]=x (mod p).

The number can be very large, just output the number modulo 1000000007 (10^9+7).
 

Input
There are multiple test cases, terminated by a line "0 0 0 0 0".

For each test case, there is a line contains five numbers p (2<p<10^18, p is a prime number) ,x (0<=x<p), l, r (0<=l<=r<=10^18) and k (1<=k<=10^18).
 

Output
For each test case, output one line "Case #k: ans", where k is the case number counting from 1, ans is the number module 10^9+7.
 

Sample Input
3 0 1 2 1 233 23 2333 23333 23 233 1 1 2 23 0 0 0 0 0
 

Sample Output
Case #1: 2 Case #2: 36003 Case #3: 2097152
 

Author
xudyh
 

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-04-25 00:48:35, Gzip enabled