Educational Codeforces Round 5 E. Sum of Remainders 数论

题意:
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-8

using 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值