Greatest common divisor and least common multiple issues

Source: Internet
Author: User
Tags greatest common divisor

Title Description Description

Enter two positive integer x0,y0 (2<=x0<100000,2<=y0<=1000000) to find the number of p,q that meet the following conditions

Condition: 1.p,q is a positive integer

2. Require p,q to x0 for greatest common divisor, y0 as least common multiple.

Trial: The number of all possible two positive integers that satisfy the condition.

Enter a description input Description

Two positive integers x0,y0

Outputs description output Description

The number of all possible two positive integers that satisfy the condition

Sample input to sample

3 60

Sample output sample outputs

4

First we need to know that the product of the two number is equal to the product of the two number greatest common divisor and least common multiple.

The proof is as follows:

Assuming that two numbers are A and B, their greatest common divisor is a/C,
Then their least common multiple are (A/C) * A (A/c) * B (A/C)
B*c after simplification
So greatest common divisor times least common multiple = (A/C) * (B*C) =a*b so the product of two numbers equals the sum of the greatest common divisor and least common multiple of these two numbers with the AC code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 intMain () {8     intx,y,num,ans=0, A,n,m,r;9Cin>>x>>y;TenNum=x*y;//num is a two-digit product One      for(intI=X;I*I&LT;NUM;I+=X) {//It can be proved that when i*i<num, the occurrence of the satisfying condition number combination is the opposite combination of the combination of numbers satisfying the condition in i*i<m, A     //I*i=num sure is not satisfied. I must be the maximum common factor x times, so direct +=x -         if(num%i==0){//guarantee that num/i is an integer -a=num/i;//another number the             if(a%x==0){//guaranteed A can be removed to the maximum common factor -n=i/x; -a=a/x; -r=n%A; +                  while(r!=0){ -r=n%A; +n=A; AA=R; at}//determine if there are any other common factor divided by n after the second number -                 if(n==1|| i/x==1)//coprime -ans+=2;//because it's both positive and negative, so just add two . -             } -              -         } in     } -cout<<ans<<Endl; to     return 0; +}

Greatest common divisor and least common multiple issues

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.