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

GuGu Convolution

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1038    Accepted Submission(s): 272


Problem Description
As a newbie, XianYu is now learning generating function!
Given a series $\{a\}=(a_0,a_1,a_2,\cdots)$, we can easily define its exponential generating function as $g_{\{a\}}(x) = \sum\limits_{i=0}^{\infty}\dfrac{a_i}{i!}x^i$.
Now we define a series $\{u_c\}=(c^0,c^1,c^2,\cdots)$ and let $e_c$ represents the ${u_c}$ with $0$ filled in all its even items. Formally, ${\{e_c\}}=(0,c^1,0,c^3,0,c^5,\cdots)$.

'Do you know convolution?'
'GU GU.' GuGu utters.
'Well, let me show you.
Given two generating function $g_{\{a\}}$ and $g_{\{b\}}$, the convolution can be represented as $G(x)=(g_{\{a\}}*g_{\{b\}})(x)=\sum\limits_{n=0}^{\infty}(\sum\limits_{i+j=n}a_ib_j)x^n$.
It is quite easy, right?'
'GU GU.' GuGu utters.
'Ok. Now you have to find the coefficient of $x^n$ of the convolution $G(x)=(g_{\{u_A\}}*g_{\{e_\sqrt{B}\}})$, given $n$, $A$ and $B$.
Let $G_n$ representes that coefficient, you should tell me $n!G_n$.
You may know the severity of unsolving this problem.'

As GuGu is not that kind of good for it, it turns to you for help.
'GU GU!' GuGu thanks.

Hint

First Sample: $1!(\dfrac{1^0}{0!}\dfrac{\sqrt{1}^1}{1!} + \dfrac{1^1}{1!}\dfrac{0}{0!}) = 1 \sqrt{1}$
Second Sample: $2!(\dfrac{523^0}{0!}\dfrac{0}{2!} + \dfrac{523^1}{1!}\dfrac{\sqrt{12}^1}{1!} + \dfrac{523^2}{2!}\dfrac{0}{0!}) = 2092 \sqrt{3}$
P.S.: $1046\sqrt{12}$ is equal to the answer. However, $12$ has a factor $4=2^2$ so it can't be output directly.
 

Input
There is an integer $T$ in the first line, representing the number of cases.
Then followed $T$ lines, and each line contains four integers $A,B,n,p$. The meaning of $A,B,n$ is described above, and that of $p$ will be described in Output session.
$1\leq T \leq 10^5$
$1\leq A,B \leq 10^6$
$1\leq n \leq 10^{18}$
$1\leq p \leq 10^{9}$
 

Output
Let $\sum\limits_{i=1}^{q} a_i\sqrt{b_i}$ represents the answer, with $b_i \neq b_j, \gcd(b_i,b_j)=1, 1\leq i< j\leq q$, and none of $b_i$'s factors is square number.
Print $T$ lines only. Each line comes with a number $q$ and followed $q$ pairs of integers $a_i$ $b_i$, with $b_i$ in increasing order. Since $a_i$ may be large, please print $a_i\%p$ instead. All integers in the same line should be seperated by exactly one space.
You may find that each answer is unique.
 

Sample Input
3 1 1 1 7 523 12 2 2100 1 1 1000000000000000000 998244353
 

Sample Output
1 1 1 1 2092 3 1 121099884 1
 

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-04 16:49:28, Gzip enabled