fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int snt(int a){
  5. int x=0;
  6. for (int i=2; i*i<=a; i++){
  7. if (a%i==0) x++;
  8. }
  9. if (x==0) return 1;
  10. else return 0;
  11. }
  12.  
  13. int main() {
  14. int n, the;
  15. cin>>n;
  16. int ntt[n], a[n];
  17. for (int i=0; i<n; i++){
  18. cin>>ntt[i];
  19. a[i]=0;
  20. }
  21. for (int i=0; i<=n; i++){
  22. if (snt(ntt[i])==1){
  23. a[i]=ntt[i];
  24. ntt[i]=0;
  25. }
  26. }
  27. for (int i=0; i<n; i++){
  28. ntt[i]=ntt[i]+a[i];
  29. cout<<ntt[i]<<" ";
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5548KB
stdin
10
10 9 8 7 6 5 4 3 2 1
stdout
10 9 8 7 6 5 4 3 2 1