题目描述

Hehe keeps a flock of sheep, numbered from 1 to n and each with a weight wi. To keep the sheep healthy, he prepared some training for his sheep. Everytime he selects a pair of numbers (a,b), and chooses the sheep with number a, a+b, a+2b, … to get trained. For the distance between the sheepfold and the training site is too far, he needs to arrange a truck with appropriate loading capability to transport those sheep. So he wants to know the total weight of the sheep he selected each time, and he finds you to help him.

输入

There’re several test cases. For each case:

The first line contains a positive integer n (1≤n≤10^5)—the number of sheep Hehe keeps.

The second line contains n positive integer wi(1≤n≤10^9), separated by spaces, where the i-th number describes the weight of the i-th sheep.

The third line contains a positive integer q (1≤q≤10^5)—the number of training plans Hehe prepared.

Each following line contains integer parameters a and b (1≤a,b≤n)of the corresponding plan.

输出

For each plan (the same order in the input), print the total weight of sheep selected.

样例输入

5

1 2 3 4 5

3

1 1

2 2

3 3

样例输出

15

6

3

提示

暴力也能过

醉了

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <stdio.h> using namespace std;
int n;
int a[100005];
int s[100005];
int q;
int b,c;
int main()
{
while(scanf("%d",&n)!=EOF)
{
s[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
s[i]=s[i-1]+a[i]; }
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
long long int ans=0;
scanf("%d%d",&b,&c); if(c==0)
{
ans=a[b];
printf("%lld\n",ans);
continue;
}
else
{
for(int j=b;j<=n;j+=c)
ans+=a[j];
}
printf("%lld\n",ans); }
}
return 0;
}

最新文章

  1. oracle的回收站介绍
  2. 【Android自定义控件】支持多层嵌套RadioButton的RadioGroup
  3. hadoop初识
  4. tidyr包--数据处理包
  5. FileWriter和FileReader简单使用
  6. linux交叉编译裁剪内核记录
  7. Android Camera拍照 压缩
  8. VC++ 视频播放器 图文步骤记录
  9. Qt Creator 代码自动补全设置
  10. angularjs控制器之间通信,事件通知服务
  11. 结对作业--基于GUI的四则运算生成器
  12. JBDC工具类
  13. Visual Studio 2013版本安装
  14. php的 $_REQUEST取值为空
  15. GAN初步——本质上就是在做优化,对于生成器传给辨别器的生成图片,生成器希望辨别器打上标签 1,体现在loss上!
  16. bzoj1294 [SCOI2009]围豆豆
  17. Netty 粘包/拆包应用案例及解决方案分析
  18. Android开发技术重要参考资料
  19. 【linux】Linux查看各类日志
  20. flume jetty 进程关系 flume jetty 跨域问题 jetty 源码分析

热门文章

  1. IE每次关闭都提示IE已停止工作
  2. [原]单片机/Stm32教程
  3. SpringMVC由浅入深day01_9商品修改功能开发
  4. phpVirtualBox – 用浏览器操作虚拟机
  5. Python中的类(中)
  6. 【GIS】ArcGIS JS 4.X
  7. Linux命令之乐--iconv
  8. 将百度编辑器ueditor用在easyui中
  9. 解决nginx中fastcgi(php-fpm)60s超时的问题
  10. TCP数据传输过程详解