您的位置:首页 > 其它

【洛谷 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  模拟 洛谷