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

Hack it!

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 183    Accepted Submission(s): 20
Special Judge


Problem Description
Let $f(s)$ be a hash function of string $s$. If $s=s_0s_1\dots s_{n-1}$,$f(s)=(\sum_{i=0}^{n-1} w(s_i)base^i) \bmod r$.

Teacher Mai wants to find two different regular bracket sequences $a,b$ with the same length$(\leq 10^4)$ and the same hash value$(f(a)=f(b))$, where w("(")=$p$,w(")")=$q$.

Let us define a regular brackets sequence in the following way: Empty sequence is a regular sequence. If $S$ is a regular sequence, then $(S)$ is regular sequences. If $A$ and $B$ are regular sequences, then $AB$ is a regular sequence.
 

Input
There are multiple test cases. All the test cases are generated randomly.

For each test case, there is one line contains four numbers $p,q,r,base(1\leq p,q,r,base\leq 10^{18})$
 

Output
For each test case, print two different regular bracket sequences $a,b$ with the same length$(\leq 10^4)$ and the same hash value$(f(a)=f(b))$
 

Sample Input
4 7 37 10
 

Sample Output
((())) ()()()
 

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-11-21 18:43:02, Gzip enabled