数学-洛谷P2261 [CQOI2007]余数求和

https://daniu.luogu.org/problem/show?pid=2261
我看不懂题解,有人看了题解马上1A,我就非常不开心;
然后就会怀疑他们抄题解;
其实是我比较傻逼而已;
给大家一个小程序;
你看透了这个程序就可以ac了~~~

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define Ll long long
using namespace std;
int main()
{
    Ll ans=0;
    for(int i=1;i<=100;i++)
    cout<<i<<' '<<100/i<<' '<<100%i<<endl,ans+=100%i;
    cout<<ans;
}

我的程序

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define Ll long long
using namespace std;
Ll ans;
Ll n,m,S,E,L;
int main()
{
    scanf("%lld%lld",&m,&n);
    if(m>n){ans+=n*(m-n);m=n;}
    S=m;
    for(int i=n/m;i<n;){
        E=n/(i+1)+1;
        L=S-E+1;
        S=n%S;
        E=S+i*(L-1);
        ans+=(S+E)*L/2;
        i++;
        S=n/i;
        i=n/S;
    }
    printf("%lld",ans);
}
posted @ 2017-03-24 10:57  largecube233  阅读(117)  评论(0编辑  收藏  举报