18.2.13 codevs1012 最大公约数和最小公倍数问题

1012 最大公约数和最小公倍数问题

2001年NOIP全国联赛普及组

 
题目描述 Description

输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数

条件:  1.P,Q是正整数

2.要求P,Q以x0为最大公约数,以y0为最小公倍数.

试求:满足条件的所有可能的两个正整数的个数.

输入描述 Input Description

二个正整数x0,y0

输出描述 Output Description

满足条件的所有可能的两个正整数的个数

样例输入 Sample Input

3 60

样例输出 Sample Output

4

 1 #include <iostream>
 2 #include<math.h>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int x,y;
 9     cin>>x>>y;
10     int z=y/x;
11     int n=0;
12     if(y%z!=0)
13         cout<<"0"<<endl;
14     else
15     {
16         for(int i=2;i<=z;i++)
17         {
18             if(z%i==0)
19             {
20                 n++;
21                 while(z%i==0)
22                     z/=i;
23             }
24         }
25         cout<<pow(2,n)<<endl;
26     }
27     return 0;
28 }
View Code

数论题总是这么又巧又短……

posted @ 2018-02-13 22:04  TobicYAL  阅读(236)  评论(0编辑  收藏  举报