博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1257: [CQOI2007]余数之和
阅读量:4600 次
发布时间:2019-06-09

本文共 1256 字,大约阅读时间需要 4 分钟。

1257: [CQOI2007]余数之和

Time Limit: 5 Sec  Memory Limit: 128 MB

Description

给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值
其中k mod i表示k除以i的余数。
例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5=0+1+0+3+3=7

Input

输入仅一行,包含两个整数n, k。
1<=n ,k<=10^9

 

Output

输出仅一行,即j(n, k)。

Sample Input

5 3

Sample Output

7

HINT

 

Source

 

x % i = x – [x / i] * i

ans = n * k -  ∑ [x / i] * i

[x / i]的值最多有√n种,枚举一下就可以啦
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 using namespace std; 9 10 template
void read (tn & a) {11 tn x = 0, f = 1;12 char c = getchar();13 while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar(); }14 while (c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }15 a = f == 1 ? x : -x;16 }17 18 long long n, k, ans;19 20 int main() {21 read(n);22 read(k);23 ans = n * k;24 n = min(n, k);25 long long j = 0; 26 for (long long i = 1; i <= n; i = j + 1) {27 long long x = k / i;28 j = k / x;29 j = min(n, j);30 ans -= x * (i + j) * (j - i + 1) / 2;31 }32 cout << ans << "\n";33 return 0;34 }
View Code

 

 

转载于:https://www.cnblogs.com/m-m-m/p/8910694.html

你可能感兴趣的文章
Symbian (Read Inbox)读取收件箱的内容
查看>>
良好的编程规范
查看>>
struts2 入门
查看>>
.net 编译原理
查看>>
mean 快速开发和现有技术的对比分析
查看>>
Metro Style app :浏览器扩展
查看>>
linux的kernel是怎样工作的(TI_DM36X_ARM系统)(1)
查看>>
[luogu4310] 绝世好题 (递推)
查看>>
[luogu3203 HNOI2010] 弹飞绵羊 (分块)
查看>>
-Dmaven.multiModuleProjectDirectory system propery is not set.
查看>>
Python2 unichr() 函数
查看>>
Python 字典 copy()方法
查看>>
Minimum Path Sum
查看>>
Remove Duplicates from Sorted Array II
查看>>
常量指针和指针常量巧妙记忆方法[转]
查看>>
python-haproxy作业讲解视频总结
查看>>
批处理文件脚本总结
查看>>
快速排序C++代码
查看>>
mui搜索框 搜索点击事件
查看>>
bzoj 5289: [Hnoi2018]排列
查看>>