数论—— 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.

 

输入

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

 

输出

Print one number — answer for the problem.
 

 

样例输入

复制样例数据

1

样例输出

1

 

提示

In the example [a,1]=a, therefore [a,b]/a is always equal to 1.

意思就是求最小公倍数再除以a的个数,明显知道大于b,结果是本身。然而会超时,所以枚举到根号b就可以了,因为后面的如果存在,肯定和前面的相乘得b,但仍然需要判断,根号b*根号b是否等于b。如果是就要减一,因为算了2遍b.

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
    ll b;
    scanf("%lld",&b);
    ll m=sqrt(b);
    ll ans=0;
    ll i;
    for(i=1;i<=m;i++){
        if(b%i==0) ans+=2;
    }
    if(m*m==b){
        ans--;
    }
    printf("%lld\n",ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值