fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fo(i,a,b) for(int i=(a);i<(b);i++)
  4. #define MOD 1000000007
  5. #define MP make_pair
  6. #define PB push_back
  7. typedef long long ll;
  8.  
  9. int N, Q, SZ=600;
  10. ll x[300300], b[600], a[300300];
  11. vector<int> dv[300300];
  12.  
  13. ll q (int i) {
  14. i--;
  15. return b[i/SZ] + x[i];
  16. }
  17.  
  18. void m (int i, ll d) {
  19. int p = (i+1)/SZ;
  20. fo(j, 0, p) b[j] += d;
  21. fo(j, p*SZ, i+1) x[j] += d;
  22. }
  23.  
  24. void u (int l, int r, ll d) {
  25. l--, r--;
  26. if (l) m(l-1, -d);
  27. m(r, d);
  28. }
  29.  
  30. int main () {
  31. fo(i, 1, 300300) {
  32. for (int j = i; j < 300300; j += i) dv[j].PB(i);
  33. }
  34.  
  35. scanf("%d", &N);
  36. fo(i, 0, N) scanf("%lld", &a[i]);
  37. scanf("%d", &Q);
  38. while (Q--) {
  39. int t; scanf("%d", &t);
  40. if (t==1) {
  41. int i; scanf("%d", &i);
  42. ll ret = 0;
  43. for (int j : dv[i]) {
  44. ret += q(j);
  45. }
  46. printf("%lld\n", ret + a[i-1]);
  47. } else {
  48. int l, r; ll d; scanf("%d %d %lld", &l, &r, &d);
  49. u(l, r, d);
  50. }
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0.2s 19824KB
stdin
Standard input is empty
stdout
Standard output is empty