zoukankan      html  css  js  c++  java
  • 求l到r的因子个数

    Boris is the chief executive officer of Rock Anywhere Transport (RAT) company which specializes in supporting music industry. In particular, they provide discount transport for many popular rock bands. This time Boris has to move a large collection of quality Mexican concert loudspeakers from the port on the North Sea to the far inland capital. As the collection is expected to be big, Boris has to organize a number of lorries to assure smooth transport. The multitude of lorries carrying the cargo through the country is called a convoy.
    Boris wants to transport the whole collection in one go by a single convoy and without leaving even a single loudspeaker behind. Strict E.U. regulations demand that in the case of large transport of audio technology, all lorries in the convoy must carry exactly the same number of pieces of the equipment.
    To meet all the regulations, Boris would like to do some planning in advance, despite the fact that he does not yet know the exact number of loudspeakers, which has a very significant influence on the choices of the number and the size of the lorries in the convoy. To examine various scenarios, for each possible collection size, Boris calculates the so-called “variability”, which is the number of different convoys that may be created for that collection size without violating the regulations. Two convoys are different if they consist of a different number of lorries.
    For instance, the variability of the collection of 6 loudspeakers is 4, because they may be evenly divided into 1, 2, 3, or 6 lorries.

    输入

    The input contains one text line with two integers N , M (1 ≤ N ≤ M ≤ 1012 ), the minimum and the maximum number of loudspeakers in the collection.

    输出

    Print a single integer, the sum of variabilities of all possible collection sizes between N and M ,inclusive.

    样例输入 Copy

    2 5
    

    样例输出 Copy

    9

    就是给你l和r,让你求l到r中每一个数的因子数的个数
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    /*
    补全成循环节,并循环至少两次 
    */ 
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+100;
    ///https://www.cnblogs.com/acm-epoch/p/13342227.html
    
    int a[10]={0,1,3,5,8,10};
    
    ll solve(ll n){
        if(n<=5)
        return a[n];
        ll sum=0;ll i;
        for(i=1;i*i<=n;i++){
            sum+=n/i-(i-1);
        }
        return sum*2-i+1;
    }
    int main(){
        ll n,m;
        scanf("%lld%lld",&n,&m);
        printf("%lld
    ",solve(m)-solve(n-1));
        
    } 
  • 相关阅读:
    机器学习-TensorFlow2.0安装简易教程
    14 深度学习-卷积
    用python画出你的童年回忆
    13-垃圾邮件分类2
    事后诸葛亮分析
    团队项目四:项目冲刺之日志集合贴
    第 1 篇 Scrum 冲刺博客
    团队作业1——团队展示&选题
    结对作业:四则运算(Java+JavaFX)
    JavaGUI之Swing简单入门示例
  • 原文地址:https://www.cnblogs.com/lipu123/p/14616788.html
Copyright © 2011-2022 走看看