hdu-1695 GCD (Möbius inversion)

Source: Internet
Author: User
Tags gcd

Topic Links:

GCD

Time limit:6000/3000 MS (java/others)

Memory limit:32768/32768 K (java/others)


problem DescriptionGiven 5 integers:a, B, C, D, K, you ' re-find x in a...b, y in C...d, GCD (x, y) = K. GCD (x, y) means the greatest co Mmon divisor of x and Y. Since the number of choices may is very large, you ' re only required to output the total number of different number pairs.
Notice that, (x=5, y=7) and (x=7, y=5) is considered to be the same.

Yoiu can assume a = c = 1 in the all test cases.

InputThe input consists of several test cases. The first line of the input is the number of the cases. There is 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 above.

OutputFor each test case, print the number of choices. Use the format in the example.

Sample Input 21 3 1 5 11 11014 1 14409 9

Sample Output Case 1:9case 2:736,427 Test Instructions:for gcd (x, y) ==k (x, y) logarithm;1<=x<=b,1<=y<=d; Ideas:gcd (x, y) =k, i.e. gcd (x/k,y/k) =1;becomes the logarithm of the coprime in [1,b/k][1,d/k];F (d) indicates the logarithm of the gcd (x, y) =d; F (d) indicates the logarithm of D|GCD (x, y);F (1) is asked here, and the Möbius inversion F (n) =∑ (n|d) Μ (d/n) F (d) is knownf (1) =∑µ (i) *f (i) (1<=i<=min (b/k,d/k)); AC Code:

hdu-1695 GCD (Möbius 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.