【洛谷 1483】 序列变换
2016-09-20 07:34
148 查看
要考虑完全平方数的情况,注意因子的取值关系。
#include <bits/stdc++.h> using namespace std; long long a1[1000010], d[1000010]; int n, m; int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i ++) scanf("%lld", &a1[i]); for(int i = 1; i <= m; i ++){ long long a, b, c; scanf("%lld", &a); if(a == 1){ scanf("%lld%lld", &b, &c); d[b] += c; }else{ scanf("%lld", &b); long long _sqrt = sqrt(b), ans = a1[b]; for(int j = 1; j <= _sqrt; j ++) if(b%j == 0) ans += (d[j]+d[b/j]); if(_sqrt*_sqrt == b) ans -= d[_sqrt]; printf("%lld\n", ans); } } return 0; }
相关文章推荐
- 【暴力】洛谷 P2038 NOIP2014提高组 day2 T1 无线网络发射器选址
- 洛谷P1418 选点问题
- 洛谷-小鱼的航程(改进版)-循环!循环!循环!
- 洛谷 P2774 方格取数问题
- [JSOI2008] [洛谷P1227] 完美的对称|乱搞
- 洛谷P1586 四方定理
- 洛谷1003 铺地毯
- 洛谷 P1602 Sramoc问题
- 洛谷1373 小a和uim之大逃离
- 洛谷 P2742 [USACO5.1]圈奶牛Fencing the Cows
- 洛谷 P1064 金明的预算方案
- 洛谷 P3478 [POI2008]STA-Station(bzoj P1131 [POI2008]STA-Station)
- 【日常学习】【数学-其他】洛谷1403 约数研究题解
- 洛谷 红魔馆OI 红色的幻想乡 [线段树]
- 洛谷1059 明明的随机数 解题报告
- 动态规划 洛谷P2365 任务安排
- 洛谷1307 数字反转
- 【CJOJ1494】【洛谷2756】飞行员配对方案问题
- 洛谷1434 滑雪
- 数列 洛谷p1062