GCD
Time Limit: 6000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 6081 accepted submission (s): 2223
Problem descriptiongiven 5 integers: A, B, C, D, K, you're trying to find X in... b, Y in C... d that gcd (x, y) = K. gcd (x, y) means the greatest common divisor of X and Y. since the number of choices may be very large, you're only required to output the total number of different number pairs.
Please notice that, (x = 5, y = 7) and (x = 7, y = 5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
Inputthe input consists of several test cases. The first line of the input is the number of the cases. There are no more than 3,000 cases.
Each case contains five integers: A, B, C, D, K, 0 <A <= B <= 100,000, 0 <C <= d <= 100,000, 0 <= k <= 100,000, as described abve. outputfor each test case, print the number of choices. use the format in the example. sample input21 3 1 5 11 11014 1 14409 9 Sample outputcase 1: 9 Case 2: 736427
HintFor the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5 ). source 2008 "sunline Cup" national invitational contest, find a Y in [c, d] So that gcd (x, y) = K (note that gcd (x, y) = K, and gcd (Y, X) = K is regarded as the same combination, although X and Y have different values ). You can find the total number of combinations. Analysis: For gcd (x, y) = K, the conventional simplification is gcd (x/K, Y/K) = 1; ---> that is, [, b] The range is reduced to [A/K, B/K]. Similarly, [c, d] is reduced to --> [C/K, D/K]. but it will still go up to the day by tle ......, what should I do? Optimization is also needed. At this time, we need to use the refresh principle.
HDU 1695 gcd (Mobius Inversion)