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 ...
随机推荐
- Unity3D笔记五 快捷键
一.近距离查看游戏对象 在Hierarchy视图中选择游戏对象,然后在Scene视图中按快捷键“F”来近距离查看该游戏对象. 二.游戏对象不在主摄像头中? Hierarchy中双击选择需要显示的游戏对 ...
- WCF学习 (三)深入认识WCF契约
什么是契约? 从SOA概念上讲,契约属于服务公开接口的一部分.一个服务契约,定义了服务端公开的服务方法,使用传输协议,可访问地址,传输的消息格式等内容.换句话说:契约描述了该服务的功能和作用,它告诉S ...
- JavaScript获取地址栏的参数!
第一种方式:手动解析 “location”对象 console.log(window.location); 使用这个对象做跳转: window.location.href=""; ...
- 浙江工业大学校赛 XiaoWei的战斗力
XiaoWei的战斗力 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Caocao's Bridges---hdu4738(桥)
http://acm.hdu.edu.cn/showproblem.php?pid=4738 题就是求出所有的桥,然后输出桥的权值的最小值. 如果一开始是不连通的,输出0. 图有重边,需要处理, 不能 ...
- Java Thread 如何处理未捕获的异常?
Java Thread是不允许异常抛出到本线程之外的,Runnable接口的public abstract void run()是不允许throws Exception的,这在编译时就通不过. 线程异 ...
- 跟我学Makefile(二)
命令出错: 每当命令运行完后, make 会检测每个命令的返回码,如果命令返回成功,那么 make 会执行下一条命令. 如果一个规则中的某个命令出错了(命令退出码非零),那么 make 就会终止执行当 ...
- Mybatis怎么在mapper中用多个参数
原文地址:https://github.com/mybatis/mybatis-3/wiki/FAQ How do I use multiple parameters in a mapper? Jav ...
- POJ2506:Tiling(递推+大数斐波那契)
http://poj.org/problem?id=2506 #include <iostream> #include <stdio.h> #include <strin ...
- t分布, 卡方x分布,F分布
T分布:温良宽厚 本文由“医学统计分析精粹”小编“Hiu”原创完成,文章采用知识共享Attribution-NonCommercial-NoDerivatives 4.0国际许可协议(http://c ...