Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders
题目连接:
http://www.codeforces.com/contest/616/problem/E
Description
The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.
input
The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.
Output
Print integer s — the value of the required sum modulo 109 + 7.
Sample Input
3 4
Sample Output
4
Hint
题意
给你n,m,让你输出n%1+n%2+n%3+....+n%m
答案需要mod1e9+7
题解:
n%i = n - i * [n/i]
所以 sigma(n%i) = n * m - sigma(i * n/i)
在一段区间内,n/i都是不会变化的,所以利用这一点,我们就可以暴力sqrt去处理就好了
但是有一些区间我们最后并没有处理到,怎么办?
直接再暴力一发去处理就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
long long n,m;
scanf("%lld%lld",&n,&m);
long long ans = (n%mod)*(m%mod)%mod;
long long S = sqrt(n+5);
long long k = m+1;
for(int i=1;i<=min(n,S);i++)
{
long long r = n / i;
long long l = n / (i+1)+1;
r = min(r,m);
if(l>r)continue;
k = min(k,l);
long long s1 = (l+r);
long long s2 = (r-l+1);
if(s1%2==0)
s1/=2LL;
else
s2/=2LL;
long long K = (s1%mod)*(s2%mod)%mod;
K = (i * K)%mod;
ans-=K;
ans%=mod;
if(ans<0)ans+=mod;
}
for(int i=1;i<k;i++)
{
ans-=(n-n%i);
ans%=mod;
if(ans<mod)ans+=mod;
}
cout<<ans%mod<<endl;
}
Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学的更多相关文章
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...
- Codeforces - Educational Codeforces Round 5 - E. Sum of Remainder
题目链接:http://codeforces.com/contest/616/problem/E 题目大意:给定整数n,m(1≤n,m≤1013), 求(n mod 1 + n mod 2 + ... ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA链上最大值
E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Descrip ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
随机推荐
- YII Framework学习教程-YII的安全
web应用的安全问题是很重要的,在“黑客”盛行的年代,你的网站可能明天都遭受着攻击,为了从某种程度上防止被攻击,YII提供了防止攻击的几种解决方案.当然这里讲的安全是片面的,但是值得一看. 官方提供的 ...
- 左侧菜单 z
Dev 的tabControl
- LoadRunner 各个指标分析
我们要监视CPU,内存.硬盘的资源情况.得到以下的参数提供分析的依据.%processor time(processor_total):器消耗的处理器时间数量.如果服务器专用于sql server 可 ...
- windows下django1.7 +python3.4.2搭建记录2
1.自定义页面写一个显示当前时间的页面views.py文件加一个使用模板的模块,整体内容为: #coding=utf-8 from django.shortcuts import render fro ...
- 挖坟之Spring.NET IOC容器初始化
因查找ht项目中一个久未解决spring内部异常,翻了一段时间源码.以此文总结springIOC,容器初始化过程. 语言背景是C#.网上有一些基于java的spring源码分析文档,大而乱,乱而不全, ...
- php基础知识(2)
数据类型整体划分 标量类型: int, float, string, bool 复合类型: array, object 特殊类型: null, resouce 整数类型int, integer 3种整 ...
- Hadoop概念学习系列之hadoop生态系统闲谈(二十五)
分层次讲解 最底层平台 ------->hdfs yarn mapreduce spark 应用层-------->hbase hive pig sparkSQL nu ...
- Spark RDD概念学习系列之RDD的缓存(八)
RDD的缓存 RDD的缓存和RDD的checkpoint的区别 缓存是在计算结束后,直接将计算结果通过用户定义的存储级别(存储级别定义了缓存存储的介质,现在支持内存.本地文件系统和Tachyon) ...
- JQuery实现的动态Table(转)
这个例子做的不错,转载备份. 原文:http://www.cnblogs.com/linjiqin/archive/2013/06/21/3148181.html $("#mytable t ...
- B - Kefa and Company
B - Kefa and Company Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...