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=nmi=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
原创粉丝点击