51nod 1225 余数的和 数学
输入1个数N(2 <= N <= 10^12)。
输出F(n) Mod 1000000007的结果。
6
3
思路:余数成等差;时间复杂度sqrt(n);
用等差数列求和的时候有个除法,所以用了下逆元;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
void extend_Euclid(ll a, ll b, ll &x, ll &y)
{
if(b == )
{
x = ;
y = ;
return;
}
extend_Euclid(b, a % b, x, y);
ll tmp = x;
x = y;
y = tmp - (a / b) * y;
}
ll mul(ll x,ll y)
{
x%=mod;
y%=mod;
return (x*y)%mod;
}
ll divi(ll x,ll y)
{
ll xx,yy;
extend_Euclid(y,mod,xx,yy);
xx=(xx%mod+mod)%mod;
return mul(x,xx);
}
int main()
{
ll x,y,z,i,t;
scanf("%lld",&z);
ll ans=;
for(i=;i<=z;i++)
{
if(z%i!=)
{
ll d=z/i;
ll maxx=(z%i)/d+;
d=-d;
ans+=mul((z%i),maxx)+divi(mul(maxx,mul((maxx-),d)),);
ans=(ans%mod+mod)%mod;
i+=maxx-;
}
}
printf("%lld\n",ans);
return ;
}
51nod 1225 余数的和 数学的更多相关文章
- 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 ...
- 51Nod 1225 余数之和 [整除分块]
1225 余数之和 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 F(n) = (n % 1) + (n % 2) + (n % 3) + ... ...
- 51nod 1225:余数之和
传送门 题意 略 分析 \(\sum_i^n(n\%i)=\sum_i^n(n-i*n/i)=n^2-\sum_i^ni*n/i\) \(=\sum r\sum_i^ni[n/i==r]\) 可以证明 ...
- BZOJ_1257_ [CQOI2007]余数之和sum_数学
BZOJ_1257_ [CQOI2007]余数之和sum_数学 题意:给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值. 分 ...
- 51nod 1225 数学
F(n) = (n % 1) + (n % 2) + (n % 3) + ...... (n % n).其中%表示Mod,也就是余数. 例如F(6) = 6 % 1 + 6 % 2 + 6 % 3 + ...
- bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1779 Solved: 823[Submit][Sta ...
- [CQOI2007]余数求和 (分块+数学
题目描述 给出正整数n和k,计算G(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod i表示k除以i的余数.例如G(10, 5)=5 ...
- 51nod 1225
题目 题解:看数据范围就估计是根号算法.考虑我们要求的式子: $ \sum\limits_{i = 1}^n {n - \left\lfloor {\frac{n}{i}} \right\rfloor ...
随机推荐
- 【UOJ274】【清华集训2016】温暖会指引我们前行 LCT
[UOJ274][清华集训2016]温暖会指引我们前行 任务描述 虽然小R住的宿舍楼早已来了暖气,但是由于某些原因,宿舍楼中的某些窗户仍然开着(例如厕所的窗户),这就使得宿舍楼中有一些路上的温度还是很 ...
- IOS项目分层
上传者:踏浪帅 分类:其他(Others) 查看次数:408 下载次数:70 上传时间:2016-01-07 大小:3 KB 主项目中的分层主要包含四个模块,Main(主要).Expand(扩展).R ...
- oracle如何四舍五入?
转自:http://www.jb51.net/article/84924.htm 取整(向下取整): 复制代码代码如下: select floor(5.534) from dual;select tr ...
- Oracle之rman命令的使用(51CTO风哥rman课程)
看rman的连接串的帮助 连接数据库 rman target/ rman的版本要和目标数据库一致(一般大版本可以往下兼容小版本) 运行操作系统命令 run {host "pwd"; ...
- Day04 dom详解及js事件
day04 dom详解 DOM的基础 Document对象 Element对象 Node对象 innerHTML 事件处理 表单验证 上次课内容回顾: JS中ECMAScript用法: JS定义变 ...
- mysql 取当前日期对应的周一或周日
select subdate(curdate(),date_format(curdate(),'%w')-1)//获取当前日期在本周的周一 select subdate(curdate(),date_ ...
- 【python】Python3 循环语句
[python]几种常见的循环 注意:如果涉及到程序中print语句中含有%d,%s,那么要在脚本最开始写语句:#coding=utf-8,才能够正常输出想要的数字或者字符串. Python3 循环语 ...
- java 多线程 day17 Exchanger
import java.util.concurrent.Exchanger;import java.util.concurrent.ExecutorService;import java.util.c ...
- Yarn框架和工作流程研究
一.概述 将公司集群升级到Yarn已经有一段时间,自己也对Yarn也研究了一段时间,现在开始记录一下自己在研究Yarn过程中的一些笔记.这篇blog主要主要从大体上说说Yarn的基本架构以及其 ...
- java.lang.UnsatisfiedLinkError: org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjava/lang/String;JZ)V
环境: Spark2.1.0 .Hadoop-2.7.5 代码运行系统:Win 7在运行Spark程序写出文件(savaAsTextFile)的时候,我遇到了这个错误: // :: ERROR U ...