zoukankan      html  css  js  c++  java
  • 【ZJNU-2424】求[a,b]之间每个数的因子和的和

    /****************************
    * Author : W.A.R            *
    * Date : 2020-09-12-19:22   *
    ****************************/
    /*
    ZJNU-2424
    求[a,b]之间每个数的因子和的和
    枚举[1,1e6]之间的因子,根据因子确定与之对应的另一个因子求和即可
    需要注意的是去重,计算方式要满足不能重复计算因子
    http://acm.zjnu.edu.cn/CLanguage/contests/1168/problems/1002.html 
    */
    #pragma GCC optimize("O3")
    #pragma G++ optimize("O3")
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<stack>
    #include<string>
    #include<set>
    #define mem(a,x) memset(a,x,sizeof(a))
    #define Rint register int
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+10;
    const int maxm=2e6+10;
    const ll mod=1e9+7;
    
    namespace Fast_IO{
        const int MAXL((1 << 18) + 1);int iof, iotp;
        char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55];
        char Getchar(){
            if (ioiS == ioiT){
                ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++);
            }else return (*ioiS++);
        }
        void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;}
        void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();}
        inline int read(){
            int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
    		if(ioc==EOF)exit(0);
            for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
        }
        inline long long read_ll(){
            long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
    		if(ioc==EOF)exit(0);
            for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
        }
        template <class Int>void Print(Int x, char ch = ''){
            if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10;
            while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch);
        }
        void Getstr(char *s, int &l){
            for(ioc=Getchar();ioc==' '||ioc=='
    '||ioc=='	';)ioc=Getchar();
    		if(ioc==EOF)exit(0);
            for(l=0;!(ioc==' '||ioc=='
    '||ioc=='	'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0;
        }
        void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);}
    } // namespace Fast_IO 
    using namespace Fast_IO;
    
    int main(){
    	ll a=read_ll(),b=read_ll(),ans=0;
    	for(ll i=1;i*i<=b;i++){
    		ll l=a/i+(a%i!=0),r=b/i;
    		l=max(i,l);
    		ans+=((l+r)*(r-l+1)/2+(r-l+1)*i);
    		if(l==i)ans-=i;
    	}
    	printf("%lld
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    面试题32
    面试题28. 对称的二叉树
    面试题55
    面试题04. 二维数组中的查找
    面试题58
    面试题57. 和为s的两个数字
    如果Python对于磁盘没有写入权限,还会运行吗?
    Python中的import语句
    Python决定一个变量时局部的,还是全局的,是在编译期
    Python中的Comprehensions和Generations
  • 原文地址:https://www.cnblogs.com/wuanran/p/13658152.html
Copyright © 2011-2022 走看看