HDU 1695 gcd (Mobius Inversion)

Source: Internet
Author: User
Tags greatest common divisor
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.