Educational Codeforces Round 5 E. Sum of Remainders
来源:互联网 发布:windows下使用ipython 编辑:程序博客网 时间:2024/06/05 02:30
E. Sum of Remainders
题目链接:点这里
题意:
求n%1+n%2+n%3+...n%m; 答案对1e9+7取模
数据范围 1<n,m<1e13
题解:
我们来看下取模运算是怎么进行的: n%i = n-n/i*i
对原式子化解成 n*m - sum(n/i*i) (1<=i<=m)
然后我们假设n/i~n/j的值是相同的。我们求j的最大值。j=n/(n/j)。
然后就可以把sum(n/i*i)看成若干个等差数列。很容易就能得到答案。
时间复杂度sqrt(n)
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<sstream>#include<algorithm>#include<vector>#include<bitset>#include<set>#include<queue>#include<stack>#include<map>#include<cstdlib>#include<cmath>#define PI 2*asin(1.0)#define LL long long#define pb push_back#define pa pair<int,int>#define clr(a,b) memset(a,b,sizeof(a))#define lson lr<<1,l,mid#define rson lr<<1|1,mid+1,r#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x)#define key_value ch[ch[root][1]][0]const LL MOD = 1000000000+7;const int N = 5e5+15;const int maxn = 1e6+1000;const int letter = 130;const int INF = 1e17;const double pi=acos(-1.0);const double eps=1e-8;using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}LL n,m;LL md(LL x){ return x%MOD;}int main(){ /// n*m-sum(n/i*i) cin>>n>>m; /// sum = n%1+n%2+n%3...n%m,sum=sum%MOD; LL ans=0,vs=0; LL j; ans=md(md(n)*md(m)); for(LL i=1;i<=min(n,m);i++){ j=n/(n/i); ///%2 if(j>m) j=m; LL pc; if((i+j)&1) pc=md(md((j-i+1)/2)*md(md(n/i)*md(i+j))); else pc=md(md(j-i+1)*md(md(n/i)*md((i+j)/2))); vs=vs+pc; vs=md(vs); i=j; } ans=md(ans-vs); if(ans<0) ans+=MOD; cout << ans << endl;
0 0
- 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 educational 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 数学公式转化
- CF-edu#5 E - Sum of Remainders -数学-枚举
- E. Sum of Remainders (数学)★
- Educational Codeforces Round 21E
- Educational Codeforces Round 26 E
- Educational Codeforces Round 903E
- 关于AndroidStudio上链接Github上传(非完整)
- Java--json序列化与反序列化
- JDBC之事务的封装和Threadlocal实例
- c++ 指针
- HDU 4115 Eliminate the Conflict 2-SAT
- Educational Codeforces Round 5 E. Sum of Remainders
- Java执行JavaScript代码
- Centeros环境中Tomcat配置域名
- CSS兼容IE6 IE7 IE8 IE9 Firefox的总结
- Azure Service、Azure Web、Azure Storm日志机制
- udp学习杂记
- 幸福指数
- PAT 乙级 1032. 挖掘机技术哪家强
- Visual Studio中自动添加默认消息映射