Educational Codeforces Round 5 E. Sum of Remainders 数论
来源:互联网 发布:数控立车车床怎么编程 编辑:程序博客网 时间:2024/05/21 18:34
题意:求∑i=1mn%i 。
思路:n%i=n−[n/i]∗i
∑i=1mn%i=n∗m−∑i=1m[n/i]∗i
因为[n/i]…[n/j]在一段上是相等的,于是可以分段计算
j=[n/[n/i]]
http://codeforces.com/contest/616/problem/E
/********************************************* Problem : Codeforces Author : NMfloat InkTime (c) NM . All Rights Reserved .********************************************/#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++) //遍历#define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --) //反向遍历#define repS(it,p) for(auto it = p.begin() ; it != p.end() ; it ++) //遍历一个STL容器#define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next) //遍历u所连接的点#define cls(a,x) memset(a,x,sizeof(a))#define eps 1e-8using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 1e5+5;const int MAXE = 2e5+5;typedef long long LL;typedef unsigned long long ULL;int T,k;LL n,m;LL MOD = 1e9+7;int fx[] = {0,1,-1,0,0};int fy[] = {0,0,0,-1,1};void input() {}LL tr(LL x) { return x % MOD;}void solve() { LL j ; LL ans = tr(tr(n)*tr(m)); LL tmp = 0; LL mm; for(LL i = 1 ; i <= min(n,m) ; i ++) { j = n / (n / i); //j是i..j区间的上界 if(j > m) j = m; if((i+j)%2==0) mm = tr((n/i)*tr(tr((i+j)/2)*tr(j-i+1))); else mm = tr((n/i)*tr(tr((j-i+1)/2)*tr(i+j))); tmp = tr(tmp+mm); i = j; } ans = tr(ans - tmp); if(ans < 0) ans += MOD; printf("%I64d\n",ans); }int main(void) { //freopen("a.in","r",stdin); while(~scanf("%I64d %I64d",&n,&m)) { input(); solve(); } return 0;}
0 0
- Educational Codeforces Round 5 E. Sum of Remainders 数论
- Codeforces educational round 5. E Sum of Remainders 数论 分块
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- Educational Codeforces Round 5 E. Sum of Remainders
- Educational Codeforces Round 5-E. Sum of Remainders
- Educational Codeforces Round 5 E. Sum of Remainders 思维 数学转换
- 【数论】【分块】【乱搞】codeforces 616E Sum of Remainders
- CodeForces 616E Sum of Remainders(数论)
- Codeforces 616E Sum of Remainders
- codeforces 616E - Sum of Remainders
- Codeforces 616E - Sum of Remainders
- CodeForces - 616E Sum of Remainders (数论)大数取余求和 好题
- Codeforces 616E Sum of Remainders 【数学分块】
- codeforces 616E Sum of Remainders 数学公式转化
- Educational Codeforces Round 26 E. Vasya's Function(数论)
- CF-edu#5 E - Sum of Remainders -数学-枚举
- E. Sum of Remainders (数学)★
- Educational Codeforces Round 21E
- ARC与非ARC混用
- Java通过文件路径下载文件
- SQL Server学习记录之获取每月每季度每年第一天和最后一天
- 字符串排序
- AndroidStudio项目从低版本导入到高版本出现的问题
- Educational Codeforces Round 5 E. Sum of Remainders 数论
- 数据平台架构基于AWS的使用总结- Redshift优劣
- 重学C++ (五) 函数
- 使用maven编译dubbo,导入eclipse(其他maven开源项目编译类似)
- iOS(五)基于XMPP的聊天:一
- [solr] - IKAnalyzer 分词加入
- Android网络时间同步
- SharedPreferences的四种模式
- 01-websocket