fork download
  1. //make a program to take an array and tell all sum of number of prime factors of it..
  2. //so make a seive array of the least prime factor of all numbers
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define n 1000000
  6. int main(){
  7.  
  8. vector<int> leasp(n,0);
  9. leasp[0]=0;
  10. leasp[1]=0;
  11. for(int i=2;i*i<n;i++)
  12. {
  13. for(int j=i*i;j<n;j+=i)
  14. {
  15. if(leasp[j]==0){
  16. leasp[j]=i;
  17. }
  18. }
  19. }
  20. //then for all of the primes we have to put that value to it
  21. for(int i=2;i<n;i++)
  22. {
  23. if(leasp[i]==0)
  24. {
  25. leasp[i]=i;
  26. }
  27. }
  28. for(int i=0;i<50;i++)
  29. {
  30.  
  31. cout<<leasp[i]<< " ";
  32. }
  33. }
  34.  
Success #stdin #stdout 0.02s 6988KB
stdin
Standard input is empty
stdout
0 0 2 3 2 5 2 7 2 3 2 11 2 13 2 3 2 17 2 19 2 3 2 23 2 5 2 3 2 29 2 31 2 3 2 5 2 37 2 3 2 41 2 43 2 3 2 47 2 7