• 数论—— 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
    ",ans);
        return 0;
    }
  • 相关阅读:
    生成密码
    生成密码
    C#委托
    C#委托
    C#委托
    最近所有博客
    win10 uwp 读写XML
    win10 uwp 读写XML
    win10 uwp 读写XML
    win10 uwp 绑定密码
  • 原文地址:https://www.cnblogs.com/skyleafcoder/p/12319545.html
Copyright © 2020-2023  润新知