fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, a[1000005];
  6. long long pre[1000005];
  7.  
  8. bool snt(int val) {
  9. for (int i = 2; i * i <= val; i++)
  10. if (val % i == 0) return false;
  11. return true;
  12. }
  13.  
  14. int main() {
  15. cin >> n;
  16. for (int i = 1; i <= n; i++)
  17. cin >> a[i], pre[i]= pre[i - 1] + a[i];
  18.  
  19. long long Mn = 1e16, Ans = -1e16;
  20.  
  21. for (int r = 2; r <= n; r++)
  22. if (snt(r)) {
  23. /// r cung the la dong vao li
  24. Mn = min(Mn, pre[r - 1]);
  25. Ans = max(Ans, pre[r] - Mn);
  26. }
  27.  
  28. cout << Ans;
  29.  
  30. }
  31.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
-10000000000000000