BZOJ 1257: [CQOI2007]余数之和
1257: [CQOI2007]余数之和
Time Limit: 5 Sec Memory Limit: 128 MB
Description
Input
Output
输出仅一行,即j(n, k)。
Sample Input
Sample Output
HINT
Source
x % i = x – [x / i] * i
ans = n * k - ∑ [x / i] * i
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector> using namespace std; template <typename tn> void read (tn & a) {
tn x = , f = ;
char c = getchar();
while (c < '' || c > ''){ if (c == '-') f = -; c = getchar(); }
while (c >= '' && c <= ''){ x = x * + c - ''; c = getchar(); }
a = f == ? x : -x;
} long long n, k, ans; int main() {
read(n);
read(k);
ans = n * k;
n = min(n, k);
long long j = ;
for (long long i = ; i <= n; i = j + ) {
long long x = k / i;
j = k / x;
j = min(n, j);
ans -= x * (i + j) * (j - i + ) / ;
}
cout << ans << "\n";
return ;
}
BZOJ 1257: [CQOI2007]余数之和的更多相关文章
- Bzoj 1257 [CQOI2007]余数之和 (整除分块)
Bzoj 1257 [CQOI2007]余数之和 (整除分块) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 一道简单题. 题目 ...
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1779 Solved: 823[Submit][Sta ...
- BZOJ 1257: [CQOI2007]余数之和sum( 数论 )
n >= k 部分对答案的贡献为 k * (n - k) n < k 部分贡献为 ∑ (k - ⌊k / i⌋ * i) = ∑ , ⌊k / i⌋ 相等的数是连续的一段, 此时这段连 ...
- BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4474 Solved: 2083[Submit][St ...
- [原博客] BZOJ 1257 [CQOI2007] 余数之和
题目链接题意: 给定n,k,求 ∑(k mod i) {1<=i<=n} 其中 n,k<=10^9. 即 k mod 1 + k mod 2 + k mod 3 + … + k mo ...
- [BZOJ 1257] [CQOI2007] 余数之和sum 【数学】
题目链接:BZOJ - 1257 题目分析 首先, a % b = a - (a/b) * b,那么答案就是 sigma(k % i) = n * k - sigma(k / i) * i ( ...
- bzoj 1257: [CQOI2007]余数之和 (数学+分块)
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 ...
- bzoj 1257 [CQOI2007]余数之和——数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 \( n\%i = n - \left \lfloor n/i \right \rfl ...
随机推荐
- redis-cluster配置
为什么要用redis-cluster 1.并发问题 redis官方生成可以达到 10万/每秒,每秒执行10万条命令假如业务需要每秒100万的命令执行呢? 2.数据量太大 一台服务器内存正常是16~25 ...
- [Leetcode 46]全排列 Permutations 递归
[题目] Given a collection of distinct integers, return all possible permutations. 数组的组合情况. Input: [1,2 ...
- Selenium+Eclipse+Python 环境搭建
第一步:安装Python 根据下面的地址,直接一键安装,全部默认方式. 下载地址:http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi 安装到 ...
- APPicon的生成
APPIcon 工厂图标的生成:http://icon.wuruihong.com/#/home
- LINUX文件删除,但磁盘空间未释放
最近在进行系统压测,由于服务器节点太多,便写了个简单的脚本,在执行过程中发现,日志文件删除后,磁盘空间只释放了一小部分,任有大部分磁盘空间未释放. 使用lsof | grep delete命令,发现已 ...
- SQLI DUMB SERIES-12
(1)检测闭合方式:在username上输入" admin" " 说明输入的username后还有双引号和括号 方法一: (2)通过其他途径知道用户名即可.如 输入&qu ...
- $\mathcal{OI}$生涯中的各种数论算法的证明
嗯,写这个是因为我太弱了\(ORZ\). #\(\mathcal{\color{silver}{1 \ \ Linear \ \ Sieve \ \ Method \ \ of \ \ Prime}} ...
- kolla单节点部署openstack
virtualbox环境: 双网卡:enp0s3(桥接) 192.168.102.194 enp0s8(桥接) 无ip 块存储 50G 关闭防火墙,selinux. 配置yum源:wget ...
- Java图片验证码学习
- Itellij Idea全局搜索
Ctrl+N按名字搜索类 1 相当于eclipse的ctrl+shift+R,输入类名可以定位到这个类文件 2 就像idea在其它的搜索部分的表现一样,搜索类名也能对你所要搜索的内容多个部分进行匹 ...