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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011469138/article/details/83722229

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;
}

猜你喜欢

转载自blog.csdn.net/u011469138/article/details/83722229