标签:12 分块 28 Factoring 次数 ull Input Output Fear
Problem C — limit 1 second
Fear Factoring
The Slivians are afraid of factoring; it’s just, well, difficult.
Really, they don’t even care about the factors themselves, just how much they sum to.
We can define F(n) as the sum of all of the factors of n; so F(6) = 12 and F(12) = 28. Your taskis, given two integers a and b with a ≤ b, to calculate
S = X a≤n≤b F(n)
Input
The input consists of a single line containing space-separated integers a and b (1 ≤ a ≤ b ≤ 1e12;b-a ≤ 1e6).
Output
Print S on a single line.
Sample
Input
101 101
Output
102
Input
28 28
Output
56
Input
1 10
Output
87
Input
987654456799 987654456799
Output
987654456800
Input
963761198400 963761198400
Output
5531765944320
Input
5260013877 5260489265
Output
4113430571304040
https://cn.vjudge.net/contest/323440#problem/C
求a到b之间的所有的数的因子之和
分块:
当n==12时:
出现次数为12的:1
出现次数为6的:2
出现次数为4的:3
出现次数为3的:4
出现次数为2的:5,6
出现次数为1的:7,8,9,10,11,12
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull f(ull n)
{
ull ans = 0;
ull left,right;
for(left = 1; left <= n; left = right+1)
{
right = n/(n/left);//块的右端点
ans += n/left*(left+right)*(right-left+1)/2;
//n/left为块中的数的出现次数
//(left+right)*(right-left+1)/2按等差数列公式求这个块的数的和
}
return ans;
}
int main()
{
ull a,b;
scanf("%llu %llu",&a, &b);
printf("%llu\n",f(b)-f(a-1));
return 0;
}
标签:12,分块,28,Factoring,次数,ull,Input,Output,Fear 来源: https://blog.csdn.net/qq_31617881/article/details/100585745
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。