CF1068B LCM

我怎么这种题都要看题解了。

[frac{operatorname{lcm}(a,b)}{a}=frac{frac{a imes b}{gcd(a,b)}}{a}=frac{b}{gcd(a,b)} ]

(a) 最大可以到 (10^{18})(b) 最大只有 (10^{10})。对于 (b) 的某个因数 (p),只需构造 (a=p) 即可得到 (gcd(a,b)=p),所以 (gcd(a,b)) 可以取遍 (b) 的所有因数,总共也就是 (b) 的因数个数种。

时间复杂度 (O(sqrt n))

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,x,y)for(i=x;i<=(y);i++)
int main()
{
	ll b;
	int i,s=0;
	cin>>b;
	For(i,1,sqrt(b))
	if(!(b%i))s+=2;
	cout<<s-(1LL*(i-1)*(i-1)==b);
	return 0;
}
原文地址:https://www.cnblogs.com/May-2nd/p/14369790.html