"NOIP2009" Hankson interesting questions

Hankson interesting questions

[Memory Limit: $ 128 MiB $] [Time limit: $ 1000 ms $]
O [Standard] [Title Type: Traditional] [Evaluation method: Text Comparison]

Title Description

Dr. Hanks is a well-known expert BT (Bio-Tech, biotechnology) field, his son named Hankson. Now, just home from school Hankson we are thinking about an interesting question.

Today, in the classroom, the teacher to explain how the sum of two positive integers $ c_1 $ and $ c_2 $ greatest common divisor and least common multiple. Now Hankson think you've mastered this knowledge, he began to think, "logarithmically Convention" and "seeking common multiple" an inverse problem of such problems, the problem is this: Given a positive integer $ a_0, a_1, b_0, b_1 $, set a positive integer $ x $ unknown satisfied:

1. $ x $ and $ a_0 A_1 $ $ $ is the greatest common divisor;
2. $ x $ and $ b_0 $ is the least common multiple of $ b_1 $.

Hankson the "inverse problem" is determined to meet the conditions of a positive integer $ x $. But after a little thought, he found that this $ x $ is not unique, may not even exist. So he turned to start thinking about how to solve the number to meet the conditions of the $ x $. Please help him solve the programming problem.

Input Format

Conduct a first positive integer $ n $, $ n-$ expressed set of input data.
The next n-$ $ lines each a set of input data, four positive integer $ a_0, a_1, b_0, b_1 $, between each two integers separated by a space.
Input data can guarantee $ a_0 $ divisible by $ a_1 $, $ b_1 $ be $ b_0 $ divisible.

Output Format

A total of $ n $ lines. The output of each input data per line, is an integer.
For each test: if there is a $ x $, $ 0 $ requested output; if there is a $ x $, please meet the conditions of an output of the number of $ X $.

Sample

Sample input

2
41 1 96 288
95 1 37 1776

Sample Output

6
2
Sample Description
A first set of input data, may be $ X $ $ $ 9,18,36,72,144,288, a total of $ 6 $;
A second set of input data, may be $ X $ $ $ 48,1776, a total of $ 2 $.

Data range and tips

For $ 50 \% $ data guaranteed $ a_0, a_1, b_0, b_1 \ leq 10 ^ 4 $ and $ n \ le 100 $.
For $ 100 \ $% of the data, to ensure that there is $ 1 \ le a_0, a_1, b_0, b_1 \ le 2 \ times 10 ^ 9 $ and $ n \ le 2000 $.

answer

Do experience problems

Thought it was number theory, determined to give up, looked at the data and found that the storm may have found half points, then ...... $ rank after $ out, found himself $ 250pts $ ......

Correct

First, the analysis for the meaning of the questions, that Italy is required

Satisfies a $ gcd (x, a_0) = a_1, lcm (x, b_0) = b_1 $ of $ x $ How much value.

So, we will analyze these relationships

First, be sure the relationship: $ a_0 \ cdot k_1 = x $

So the same token, this relationship is also certainly exists: $ x \ cdot k_2 = b_1 $

So comprehensive look at these two equations, we can get: $$ a_0 \ cdot k_1k_2 = x \ cdot k_2 = b_1 $$

Then scratched the surface of understanding what, if $ b_1% a_0 ≠ 0 $, then the answer is certainly of $ 0 $.


 

We first set $ x = {p_1} ^ {k_1} {p_2} ^ {k_2} ...... {p_n} ^ {k_n} $

Then, based on $ a_0, a_1 $ and $ b_0, b_1 $ analysis they were there any restrictions for $ x $.

First, we look at the first set of $ a_0, a_1 $

Let's set up

$a_0={b_1}^{t_1}{b_2}^{t_2}......{b_m}^{t_m}$

$a_1={c_1}^{q_1}{c_2}^{q_2}......{c_v}^{q_v}$

$ $ GCD first definition, we can know every $ q_i = min \ {k_i, t_i \} $

So let's talk about:

  • When $ q_i = t_i $, $ k_i≥t_i $, $ X $ in the case described a factor P_i $ $ $ K_i $ least one, but infinite number
  • When the $ q_i ≠ t_i $, if $ q_i <t_i $ no solution, otherwise it must meet the $ k_i = t_i $

You can then were counted.

For the second group, can be analyzed using the same method, the details will not be repeated.

Lost code:

Want to see the code? Also code ......

 

Guess you like

Origin www.cnblogs.com/MachineryCountry/p/11715618.html