zoukankan      html  css  js  c++  java
  • 数论—— 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;
    }
  • 相关阅读:
    db.Exec和db.Query的区别
    golang两种get请求获取携带参数的方式
    gin实现中间件middleware
    gin操作session
    笔札-有触动的句子
    并发的基本概念
    售货员的难题
    传球游戏之最小总代价
    状压dp入门
    [COCI 2010] OGRADA
  • 原文地址:https://www.cnblogs.com/skyleafcoder/p/12319545.html
Copyright © 2011-2022 走看看