Responsive image

问题 1873 --Engineering of the Clones

1873: Engineering of the Clones

时间限制: 2 Sec  内存限制: 128 MB
提交: 1  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

> Cloning was the process of creating a genetically identical or—purposefully and specifically—modified copy of an original organism. It was also one of the key factors that facilitated the end of the Galactic Republic and the dawn of the Galactic Empire in its place. Through the science of cloning, a vast clone army was created on Kamino for the purpose of serving the Republic. Programmed with absolute loyalty to Supreme Chancellor Palpatine, leader of the Galactic Senate and secretly the Sith Lord Darth Sidious, the clones proved to be instrumental in his rise to the position of Emperor. The military applications of cloning were further exploited by the New Order through the creation of countless more clone soldiers, all used mainly for the sole purpose of spreading and enforcing Imperial hegemony throughout the galaxy.
>
> — Wookieepedia
The clones are engineered such that all have exactly the same genetic footprint, and are flash-learned directly from a template. Thus, all clones should be completely identical to the original person in theory. However, the cloning procedure is proven to be defective. A clone may be physically deformed and will die in his early age, or even worse, a seemingly functional clone may also have tiny defects in the brain development that may leak secretly programmed information. During the Clone War, such a rare case was reported: a Jedi was killed by a malfunctioning clone believed that the Order 66 has been issued, and the case nearly lead to the Jedi Council to discover the secret plan of the evil Darth Sidious.
After the malfunctioning case was reported, Chancellor Palpatine decided to carefully test all clones before they are being delivered to the battlefield. This is done by a procedure called "high-precision genome fingerprinting" that balances the time and the money. In particular, the entire gnome of a clone is taken and encoded as a single number. Only one digit of that number is actually sampled and tested.
Given genes denoted by prime numbers p1,p2,..,pn, the genome of the clone is represented by a number A defined as 
A=pr11pr22..prnn

where 
∣∣ri−rj∣∣≤1,1≤i≤j≤n.

Since A may be huge in size, the test process only samples one digit as the fingerprint: the k-th digit of 1/(A−1) written in base ∏ni=1pi.
You received the mission of designing an algorithm to perform the genome fingerprinting test. Given a genome description (pi and ri) and k, you should find the fingerprint value.
 

输入描述

The first line of the input contains an integer T, denoting the number of test cases. 
For each test case, the first line contains two integers n (1≤n≤10^6) and k (1≤k<max{r21,r22,..,r2n}). 
The next line contains n distinct primes. The i-th number is pi 1≤∏ni=1pi≤10^6.
The next line contains n integers. The i-th number is ri (1≤ri≤5∗10^4).
 

输出描述

You should output the answers for the queries, one integer per line. 
 

样例输入

1
2 1
2 5
2 2

样例输出

0

来源

 

[提交][状态]
ACM算法攻关部
  • Anything about this OnlineJudge, Please Contact Administrator. Click add QQ

    OJ system based on HUSTOJ Project , UI based on Twitter Bootstrap

    Copyright 2016 ACM算法攻关部
    关于网站改版