18.2.13 codevs1012 最大公約數和最小公倍數問題
阿新 • • 發佈:2018-02-14
end scrip body math iostream pen 分享 name 約數和
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 Input3 60
樣例輸出 Sample Output4
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 elseView Code15 { 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}
數論題總是這麽又巧又短……
18.2.13 codevs1012 最大公約數和最小公倍數問題