fork download
  1. const size=300;
  2. var d:array[-301..300001,0..301] of int64;
  3. a:array[0..1000000] of int64;
  4. i,n,j,q,poz:longint;
  5. sum,x,y:int64;
  6.  
  7. begin
  8. read(n);
  9. for i:=1 to n do
  10. read(a[i]);
  11.  
  12.  
  13. for i:=1 to n do
  14. for j:=1 to size do
  15. d[i][j]:=d[i-j][j]+a[i];
  16.  
  17.  
  18. read(q);
  19.  
  20. for i:=1 to q do
  21. begin
  22. read(x,y);
  23. sum:=0;
  24. if y>size then
  25. begin
  26. j:=x;
  27. while (j<=n) do
  28. begin
  29. sum:=sum+a[j];
  30. j:=j+y;
  31. end;
  32. writeln(sum);
  33. end
  34. else
  35. begin
  36. poz:=(n-x) div y;
  37. writeln(d[poz*y+x][y]-d[x-y][y]);
  38. end;
  39. end;
  40. end.
  41.  
  42.  
  43.  
Success #stdin #stdout 0s 716800KB
stdin
Standard input is empty
stdout
Standard output is empty