Codeforces Round #518 (Div. 2) B. LCM 因数分解

本文介绍了一个基于数论的问题,即给定一个整数b,求从1到10^18范围内所有与b的最小公倍数(LCM)不同的数量。通过分析,将问题转化为求b的因数个数,提供了详细的解题思路和C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. LCM

Ivan has number b. He is sorting through the numbers a from 1 to 1018, and for every a writes [a,b]a on blackboard. Here [a,b] stands for least common multiple of a and b. Ivan is very lazy, that’s why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.

Input
The only line contains one integer — b (1≤b≤1010).

Output
Print one number — answer for the problem.

Examples
inputCopy
1
outputCopy
1
inputCopy
2
outputCopy
2
Note
In the first example [a,1]=a, therefore [a,b]a is always equal to 1.

In the second example [a,2] can be equal to a or 2⋅a depending on parity of a. [a,b]a can be equal to 1 and 2.
这题可以是基础数论,我们知道数m,n的最小公倍数等于(m*n)/gcd(m,n),所以这题可以化简为b/gcd(a,b),所以题意就是gcd(a,b)的个数,也就是b的因数的个数,

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<bits/stdc++.h> 
using namespace std;

int main()
{
	
	long long b,ans=0;
	cin>>b;
	
	for(int i=1;i<sqrt(b+1);i++)
		if((b%i)==0)
		{
			ans+=2;
		if(b/i==i) ans--;
		}
		
	if(b==1||b==0)
		ans=1;
	cout<<ans<<endl;
	
	
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值