pascal代码,数学数列知识,直接贴码,不多说
program U34202;
var
i,a,b:longint;
sum,k,c,w:int64;
begin
{assign(input,'1.txt');reset(input);
assign(output,'2.txt');rewrite(output);}
readln(a,b);
k:=1;
c:=b div 2;
sum:=0;
if a=1 then begin dec(sum);a:=2;end;
for i:=1 to c do
begin
k:=k*(-1);
if a>=2*i+1 then w:=a div i else w:=2;
sum:=sum+k*i*((w+b div i)*(b div i-w+1) div 2);
sum:=sum-k*((i-((a div i+1)*i-a))*(a div i));
sum:=sum-k*((i-(b-(b div i-1)*i)+i-1)*(b div i));
end;
for i:=a to b do
if (i-i div 2) mod 2<>0 then
begin
if (i div 2) mod 2=1 then inc(sum)
else dec(sum);
end;
writeln(sum);
{close(input);
close(output);}
end.
另一种
var ans,a,b,g:int64; i:longint;
function pd(x:longint):longint;begin if x mod 2=1 then exit(-1) else exit(1);end;
function js(x,y:int64):int64;begin js:=(((1+x)*x)div 2)*y;end;
begin {assign(input,'4.txt');reset(input); assign(output,'3.txt');rewrite(output);} readln(a,b); g:=b-a+1; ans:=0; for i:=1 to a do ans:=ans+pd(i)*(js((b-i)div i,i)+(b mod i+1)*(b div i)-js((a-i-1)div i,i)-((a-1) mod i+1)*((a-1) div i)); for i:=a+1 to b do ans:=ans+pd(i)*(js((b-i)div i,i)+(b mod i+1)*(b div i)); writeln(ans); {close(input); close(output);}end.
program U34202;
var
i,a,b:longint;
sum,k,c,w:int64;
begin
{assign(input,'1.txt');reset(input);
assign(output,'2.txt');rewrite(output);}
readln(a,b);
k:=1;
c:=b div 2;
sum:=0;
if a=1 then begin dec(sum);a:=2;end;
for i:=1 to c do
begin
k:=k*(-1);
if a>=2*i+1 then w:=a div i else w:=2;
sum:=sum+k*i*((w+b div i)*(b div i-w+1) div 2);
sum:=sum-k*((i-((a div i+1)*i-a))*(a div i));
sum:=sum-k*((i-(b-(b div i-1)*i)+i-1)*(b div i));
end;
for i:=a to b do
if (i-i div 2) mod 2<>0 then
begin
if (i div 2) mod 2=1 then inc(sum)
else dec(sum);
end;
writeln(sum);
{close(input);
close(output);}
end.
另一种
var ans,a,b,g:int64; i:longint;
function pd(x:longint):longint;begin if x mod 2=1 then exit(-1) else exit(1);end;
function js(x,y:int64):int64;begin js:=(((1+x)*x)div 2)*y;end;
begin {assign(input,'4.txt');reset(input); assign(output,'3.txt');rewrite(output);} readln(a,b); g:=b-a+1; ans:=0; for i:=1 to a do ans:=ans+pd(i)*(js((b-i)div i,i)+(b mod i+1)*(b div i)-js((a-i-1)div i,i)-((a-1) mod i+1)*((a-1) div i)); for i:=a+1 to b do ans:=ans+pd(i)*(js((b-i)div i,i)+(b mod i+1)*(b div i)); writeln(ans); {close(input); close(output);}end.