Codeforces Round #518 (Div. 2) B LCM

传送门

https://www.cnblogs.com/violet-acmer/p/10163375.html

 

题解:

  这道题有点意思,有点数学的味道。

  根据定义“[a,b] / a”可得这求得是lcm(a,b) / a。

  转换一下:

  易知 gcd(a,b)= (a*b) / lcm(a,b) <=> lcm(a,b) = (a*b) / gcd(a,b)

  那么 lcm(a,b) / a <=> b / gcd(a,b)

  而gcd(a,b)不就是b的约数吗?

  因为 a 取的最大值为 1018  ;

  而 b 的最大值才为 1010 ;

  所以这道题直接转化为求 b 的约数个数了.

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 #define ll __int64
 8 
 9 ll b;
10 int Prime()
11 {
12     int res=2;
13     int x=sqrt(b);
14     for(int i=2;i <= x;++i)
15     {
16         if(b%i != 0)
17             continue;
18         res++;
19         if(b/i != i)
20             res++;
21     }
22     return (b == 1 ? 1:res);
23 }
24 int main()
25 {
26     scanf("%I64d",&b);
27     printf("%d\n",Prime());
28     return 0;
29 }
View Code

 

posted @ 2018-12-23 11:14  HHHyacinth  阅读(158)  评论(0编辑  收藏  举报