fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int M = 5005;
  4. const int M2 = 2500005;
  5. int n, a[M], so_uoc[M2];
  6. long long t[M], kq, d;
  7.  
  8.  
  9. int suoc(long long y)
  10. {
  11. if(y <= M2)
  12. {
  13. if(so_uoc[y-1]) return so_uoc[y-1];
  14. }
  15. int dem = 0;
  16. for(int i = 1; 1ll*i*i <= y; i++)
  17. {
  18. if(y%i == 0)
  19. {
  20. dem++;
  21. if(i != y/i) dem++;
  22. }
  23. }
  24. if(y <= M2) so_uoc[y-1] = dem;
  25. return dem;
  26. }
  27.  
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0); cout.tie(0);
  32. cin >> n;
  33. for(int i = 1; i <= n; i++)
  34. {
  35. cin >> a[i];
  36. t[i] = t[i-1] + a[i];
  37. }
  38. for(int v = 1; v < n; v++)
  39. {
  40. for(int w = v+1; w <= n; w++)
  41. {
  42. d = t[w] - t[v];
  43. kq += 1ll * v * suoc(d);
  44. }
  45. }
  46. cout << kq;
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 5564KB
stdin
4
250005
250005
250005
250005
stdout
216