Advertisement
csetanzil

Untitled

Nov 9th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. ///Summation of prime number
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. long prime(long n)
  5. {
  6. long sum=0;
  7. int i,j;
  8. for(i=2;i<=n;i++)
  9. {
  10. int f = 0;
  11. if(i==2)
  12. {
  13. sum = sum+2;
  14. continue;
  15. f++;
  16. }
  17. for(j=2;j<=i/2;j++)
  18. {
  19. if(i%j==0)
  20. {
  21. f =1;
  22. break;
  23. }
  24. }
  25. if(f==0)
  26. sum = sum+i;
  27. }
  28. return sum;
  29. }
  30. int main()
  31. {
  32. long t,i;
  33. long n,*sum,*temp;
  34. cin>>t;
  35. sum = new long;
  36. temp = sum;
  37. for(i=0;i<t;i++)
  38. {
  39. cin>>n;
  40. *sum = prime(n);
  41. sum++;
  42. }
  43. for(i=0;i<t;i++)
  44. {
  45. if(*temp==1)
  46. continue;
  47. cout<<*temp<<endl;
  48. temp++;
  49. }
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement