题解 [51nod1225]余数之和
题解 [51nod1225]余数之和
题面
解析
首先可以发现,\(a\)%\(b\)\(=a-b*\lfloor a/b \rfloor\).
而对于一段连续的\(b\)来说\(\lfloor a/b\rfloor\)是一样的.
并且这一段\(b\)是等差数列.
因此整除分块搞一搞就行了.
数据范围真的恶心(爆longlong)
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define int __int128
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
}
const int Mod=1000000007;
int n,ans;
inline int fpow(int a,int b){
int ret=1;
for(;b;a=a*a%Mod,b>>=1) if(b&1) ret=ret*a%Mod;
return ret;
}
signed main(){
n=read();int inv=fpow(2,Mod-2);
for(int l=1,r;l<=n;l=r+1){
r=n/(n/l);
ans=(ans+(n/l)*inv%Mod*(l+r)%Mod*(r-l+1)%Mod)%Mod;
}
ans=((n%Mod)*(n%Mod)-ans)%Mod;
long long ret=(ans+Mod)%Mod;
printf("%lld\n",ret);
return 0;
}
题解 [51nod1225]余数之和的更多相关文章
- 51nod1225 余数之和
打表可以看出规律.分块求就可以了. #include<cstdio> #include<cstring> #include<cctype> #include< ...
- 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 2001 Solved: 928[Submit][Sta ...
- 【BZOJ1257】余数之和(数论分块,暴力)
[BZOJ1257]余数之和(数论分块,暴力) 题解 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + - + k mod n的 ...
- 1257: [CQOI2007]余数之和
题目链接 bzoj1257: [CQOI2007]余数之和 题解 数论分块,乘等差数列求和 代码 #include<bits/stdc++.h> using namespace std; ...
- 51nod 1225 余数之和 数论
1225 余数之和 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 Description F(n) ...
- 51Nod 1225 余数之和 —— 分区枚举
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 1225 余数之和 基准时间限制:1 秒 空间限制:1 ...
- 【bzoj1257】[CQOI2007]余数之和sum
[bzoj1257][CQOI2007]余数之和sum 2014年9月1日1,9161 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod ...
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- 【BZOJ1257】【CQOI2007】余数之和sum
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, ...
随机推荐
- 共阳极RGB LED二极管
1)RGB LED二极管有四个引脚,它把3个普通led被封装在其内部,这三个led颜色分别为红.绿.蓝三种颜色,通过控制各个LED的亮度,你可以混合出几乎任何你想要的颜色,如下图: 2)RGB LED ...
- PB笔记之导入、导出组件
导入组件 导出组件
- FPS 游戏实现D3D透视
FPS游戏可以说一直都比较热门,典型的代表有反恐精英,穿越火线,绝地求生等,基本上只要是FPS游戏都会有透视挂的存在,而透视挂还分为很多种类型,常见的有D3D透视,方框透视,还有一些比较高端的显卡透视 ...
- oracle-3-Linux-11g安装-静默安装
oracle下载地址:https://www.oracle.com/database/technologies/112010-linx8664soft.html 系统是最小化安装的Centos7.2 ...
- PG SQL funcation
create extension IF NOT EXISTS "uuid-ossp" ; --select uuid_generate_v4(); --select current ...
- Mybatis:缓存
1.什么是缓存[Cache] 存在内存中的临时数据. 将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统 ...
- nginx 反向代理配置(一)
文章参考:https://blog.csdn.net/physicsdandan/article/details/45667357 什么是代理? 代理在普通生活中的意义就是本来 ...
- Android利用系统原生BottomNavigationView实现底部导航
<android.support.design.widget.BottomNavigationView android:id="@+id/navigation" androi ...
- springboot学习入门简易版一---springboot2.0介绍
1.1为什么用springboot(2) 传统项目,整合ssm或ssh,配置文件,jar冲突,整合麻烦.Tomcat容器加载web.xml配置内容 springboot完全采用注解化(使用注解方式启动 ...
- 软件自带依赖库还是共享对象库/为什么linux发行版之间不能有一个统一的二进制软件包标准
接前文:Linux软件包(源码包和二进制包)及其区别和特点 在前文,我们知道了linux软件包分为源码包和二进制包两种方式,而不同的发行版之间又有着自己的二进制打包格式. 首先,软件运行依赖着各种各样 ...