[jzoj]3729. 【NOIP2014模拟7.10】表达式的值(exp) (分块转化模型)

来源:互联网 发布:.域名的续费是怎么回事 编辑:程序博客网 时间:2024/05/17 08:08

Link

https://jzoj.net/senior/#contest/show/1937/0

Problem

1nn mod i

Data constraint

对于 60%的数据,1n5,000
对于 100%的数据,1n1,000,000,000.

Solution

60%

直接模拟即可

100%

考虑转化模型.

1nn mod i=1nnini=n21nini

ni可以用分块在O(sqrt(n))的时间内处理.

故总的时间复杂度为O(sqrt(n))

Code

var        ans,t,t1,x,n:qword;        i:longint;begin        readln(n);        for i:=1 to trunc(sqrt(n)) do        begin                t:=n div i;                t1:=n div (i+1);                inc(ans,((t+t1+1)*(t-t1) div 2)*i);                x:=n div i;                if (x<=i) then continue;                t:=n div x;                t1:=n div (x+1);                inc(ans,((t+t1+1)*(t-t1) div 2)*x);        end;        writeln(n*n-ans);end.
0 0
原创粉丝点击