ZOJ 1577 GCD & amp; LCM

Source: Internet
Author: User

This question is very watery, But WA is a lot better. I want to crash, but I have to pay attention to it. I suddenly found that there are still 0 possibilities. The simple method is enumeration. Set p = a * x; q = B * x; a and B must be of mutual quality, and a * B = y/x, when y % x! = 0 is definitely not possible. Then enumerate the numbers of mutual quality a and B multiplied by 2.

Code:


[Cpp]
# Include <iostream>
# Include <stdio. h>
Using namespace std;
 
Int GCD (int a, int B)
{
If (B = 0) return;
Return GCD (B, a % B );
}
Int Solve (int n)
{
Int cnt = 1, I;
For (I = 2; I * I <n; I ++ ){
If (n % I! = 0 | n/I % I = 0) continue;
If (GCD (n/I, I) = 1)
Cnt ++;
} Www.2cto.com
Return cnt * 2;
}
Int main ()
{
Int x, y;
While (scanf ("% d", & x, & y )! = EOF ){
If (y % x! = 0) printf ("0 \ n ");
Else if (x = y) printf ("1 \ n ");
Else if (x = 1) printf ("2 \ n ");
Else printf ("% d \ n", Solve (y/x ));
}
Return 0;
}

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.