#3011. DZY Loves Math III

DZY Loves Math III

Description

Format

Input

Output

Samples

3
1
2
3
2
4
2
6

Limitation

1<=N<=10,0<=Qi<=10^18,1<=Pi<=10^18,P>=2