(number theory) greatest common divisor and least common multiple problems

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

Output description Output Description

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

Sample input Sample Input

3 60

Sample output Sample Output

4

Data size & Hint

3 60

60 3

12 15

15 12

Idea: y/x then decomposes factorization and then the power of 2 is the answer.

1#include <stdio.h>2#include <math.h>3 intx, y;4 BOOLZhiintx)5 {6       for(intI=2; i<=sqrt (x); + +i)7          if(x%i==0)return 0;8      return 1;9 }Ten intMain () One { Ascanf"%d%d",&x,&y); -     if(y%x!=0) -     { theprintf"0/n"); -                return 0; -     } -x=y/x; y=0; +      for(intI=2; i<=x;++i) -         if(Zhi (i)) +         {  A                    if(x%i==0) ++y; at                     while(x%i==0) x/=i; -         } -printf"%d/n",(int) Pow (2, y)); -     return 0; -}
View Code

(number theory) greatest common divisor and least common multiple problems

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.