数学 CF1068B LCM

CF1068B LCM

给定一个正整数(b (1leq b leq 10^{10}))。 把一个正整数a从1枚举到(10^{18}),求有多少种不同的(large frac{[a,b]}{a})

分析:

[(a,b)*[a,b]=a*b\-->frac{[a,b]}{a}=frac{b}{(a,b)} ]

​ b是不变的,那么答案就是(frac{b}{(a,b)})的个数,又又因为b不变,答案就是((a,b))的个数,又又又因为b不变,答案就是b的因子的个数。

​ 有趣

code:

#include <iostream>
#include <cstdio>

#define int long long

using namespace std;

inline int read(){
	int sum=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<1)+(sum<<3)+ch-'0'; ch=getchar();}
	return sum*f;
}

int ans,b;

signed main(){
	b=read();
	for(int i=1;i*i<=b;i++)
		if(b%i==0)
			if(i*i!=b)ans+=2;
			else ans++;
	printf("%lld
",ans);
	return 0;
}
原文地址:https://www.cnblogs.com/wangxiaodai/p/9925883.html